#include <bits/stdc++.h>
using namespace std;
long long b[1000 + 10];
long long c[1000 + 10];
long long v[1000 + 10];
bool cmp(long long x, long long y) { return b[x] < b[y]; }
bool cmt(long long x, long long y) { return c[x] < c[y]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n + 10][m + 10];
  long long numstr[n + 10][m + 10];
  long long numstb[n + 10][m + 10];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  long long mxstr[n + 10];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) b[j] = a[i][j];
    for (int i = 1; i <= 1000; ++i) v[i] = i;
    sort(v + 1, v + m + 1, cmp);
    long long mx = 1;
    numstr[i][v[1]] = mx;
    for (int j = 2; j <= m; ++j) {
      if (b[v[j]] > b[v[j - 1]]) mx++;
      numstr[i][v[j]] = mx;
    }
    mxstr[i] = mx;
  }
  long long mxstb[m + 10];
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) c[i] = a[i][j];
    for (int i = 1; i <= 1000; ++i) v[i] = i;
    sort(v + 1, v + n + 1, cmt);
    long long mx = 1;
    numstb[v[1]][j] = mx;
    for (int i = 2; i <= n; ++i) {
      if (c[v[i]] > c[v[i - 1]]) mx++;
      numstb[v[i]][j] = mx;
    }
    mxstb[j] = mx;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cout << max(mxstr[i] - numstr[i][j] + max(numstr[i][j], numstb[i][j]),
                  mxstb[j] - numstb[i][j] + max(numstr[i][j], numstb[i][j]))
           << " ";
    }
    cout << endl;
  }
  return 0;
}
