#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
int n, m, d;
int a[MAX][MAX];
vector<int> row[MAX];
vector<int> col[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> d;
      a[i][j] = d;
      row[i].push_back(d);
      col[j].push_back(d);
    }
  }
  for (int i = 0; i < n; i++) {
    sort(row[i].begin(), row[i].end());
    row[i].erase(unique(row[i].begin(), row[i].end()), row[i].end());
  }
  for (int j = 0; j < m; j++) {
    sort(col[j].begin(), col[j].end());
    col[j].erase(unique(col[j].begin(), col[j].end()), col[j].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ele = a[i][j];
      int lr = lower_bound(row[i].begin(), row[i].end(), ele) - row[i].begin();
      int lc = lower_bound(col[j].begin(), col[j].end(), ele) - col[j].begin();
      int gr = row[i].end() - upper_bound(row[i].begin(), row[i].end(), ele);
      int gc = col[j].end() - upper_bound(col[j].begin(), col[j].end(), ele);
      cout << max(lc, lr) + 1 + max(gr, gc) << " ";
    }
    cout << "\n";
  }
  return 0;
}
