#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 1e2;
int n, m;
int mp[maxn][maxn];
int row[maxn][maxn], col[maxn][maxn];
int toprow[maxn], topcol[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &mp[i][j]);
      row[i][j] = col[j][i] = mp[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    sort(row[i] + 1, row[i] + m + 1);
    toprow[i] = unique(row[i] + 1, row[i] + 1 + m) - (row[i] + 1);
  }
  for (int i = 1; i <= m; ++i) {
    sort(col[i] + 1, col[i] + 1 + n);
    topcol[i] = unique(col[i] + 1, col[i] + 1 + n) - (col[i] + 1);
  }
  int trow, tcol;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      trow = lower_bound(row[i] + 1, row[i] + 1 + toprow[i], mp[i][j]) -
             (row[i] + 1);
      trow += 1;
      tcol = lower_bound(col[j] + 1, col[j] + 1 + topcol[j], mp[i][j]) -
             (col[j] + 1);
      tcol += 1;
      cout << max(trow, tcol) + max(toprow[i] - trow, topcol[j] - tcol) << " ";
    }
    cout << endl;
  }
  return 0;
}
