#include <bits/stdc++.h>
using namespace std;
void Weapons19() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  Weapons19();
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> v(n, vector<long long>(m)),
      v2(m, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> v[i][j];
      v2[j][i] = v[i][j];
    }
  }
  vector<vector<long long>> z = v;
  for (long long i = 0; i < n; i++) sort(z[i].begin(), z[i].end());
  for (long long i = 0; i < m; i++) sort(v2[i].begin(), v2[i].end());
  vector<map<long long, long long>> mc(m);
  vector<map<long long, long long>> mr(n);
  vector<long long> valc(m, 0), valr(n, 0);
  long long prev = -1, c = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (z[i][j] != prev) {
        prev = z[i][j];
        c++;
      }
      mr[i][z[i][j]] = c;
    }
    valr[i] = c;
    prev = -1;
    c = 0;
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      if (v2[i][j] != prev) {
        prev = v2[i][j];
        c++;
      }
      mc[i][v2[i][j]] = c;
    }
    valc[i] = c;
    prev = -1;
    c = 0;
  }
  long long ans, a;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      long long x = v[i][j];
      if (mr[i][x] >= mc[j][x]) {
        a = mr[i][x];
        ans = max(valr[i], a + valc[j] - mc[j][x]);
      } else {
        a = mc[j][x];
        ans = max(a + valr[i] - mr[i][x], valc[j]);
      }
      cout << ans << " ";
    }
    cout << "\n";
  }
}
