#include <bits/stdc++.h>
using namespace std;
map<int, int> col[1005], row[1005];
int rm[1005];
int cm[1005];
int work[1005][1005];
int main(void) {
  int i, j, k;
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      cin >> work[i][j];
    }
  }
  for (i = 1; i <= n; ++i) {
    vector<int> hh;
    for (j = 1; j <= m; ++j) {
      hh.push_back(work[i][j]);
    }
    sort(hh.begin(), hh.end());
    int len = unique(hh.begin(), hh.end()) - hh.begin();
    for (j = 0; j <= len - 1; ++j) {
      row[i][hh[j]] = j + 1;
    }
    rm[i] = len;
  }
  for (i = 1; i <= m; ++i) {
    vector<int> hh;
    for (j = 1; j <= n; ++j) {
      hh.push_back(work[j][i]);
    }
    sort(hh.begin(), hh.end());
    int len = unique(hh.begin(), hh.end()) - hh.begin();
    for (j = 0; j <= len - 1; ++j) {
      col[i][hh[j]] = j + 1;
    }
    cm[i] = len;
  }
  int tt;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      if (row[i][work[i][j]] > col[j][work[i][j]]) {
        cout << max(rm[i], row[i][work[i][j]] - col[j][work[i][j]] + cm[j]);
      } else {
        cout << max(cm[j], col[j][work[i][j]] - row[i][work[i][j]] + rm[i]);
      }
      cout << " ";
    }
    cout << endl;
  }
  return 0;
}
