#include <bits/stdc++.h>
using namespace std;
long long MOD = int(1e9) + 7;
int debug = 1;
const int N = int(1e5) + 5;
using namespace std;
const int M = int(1e3) + 5;
int a[M][M];
int row[M][M], col[M][M], maxrow[M], maxcol[M];
int main() {
  int i, j, n, t, m;
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++) {
    vector<int> b;
    for (j = 0; j < m; j++) {
      b.push_back(a[i][j]);
    }
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    ;
    maxrow[i] = b.size();
    for (j = 0; j < m; j++) {
      row[i][j] = (lower_bound(b.begin(), b.end(), a[i][j]) - b.begin()) + 1;
    }
  }
  for (j = 0; j < m; j++) {
    vector<int> b;
    for (i = 0; i < n; i++) {
      b.push_back(a[i][j]);
    }
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    ;
    maxcol[j] = b.size();
    for (i = 0; i < n; i++) {
      col[i][j] = (lower_bound(b.begin(), b.end(), a[i][j]) - b.begin()) + 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      int val = max(row[i][j], col[i][j]);
      int ans = max(val - row[i][j] + maxrow[i], val - col[i][j] + maxcol[j]);
      cout << ans << " ";
    }
    cout << endl;
  }
}
