#include <bits/stdc++.h>
using namespace std;
const long long N = 1000;
long long a[N][N], c[N][N], d[N][N], f[N], g[N], dp[N], y[N], s[N], h[N][N],
    h1[N][N], id[N], id1[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    vector<pair<long long, long long> > qq;
    map<long long, long long> ss;
    set<long long> aa;
    set<long long>::iterator it;
    for (long long j = 0; j < m; j++) {
      qq.push_back({a[i][j], j});
      aa.insert(a[i][j]);
    }
    long long k = 0;
    for (it = aa.begin(); it != aa.end(); it++) {
      ss[*it] = k;
      k++;
    }
    for (long long j = 0; j < m; j++) {
      h[i][j] = ss[a[i][j]];
    }
    sort(qq.begin(), qq.end());
    for (long long j = 0; j < m; j++) dp[i] = 0;
    dp[0] = 1;
    long long x = qq[0].second;
    c[i][x] = dp[0];
    for (long long j = 1; j < m; j++) {
      dp[j] = dp[j - 1];
      if (qq[j].first > qq[j - 1].first) dp[j]++;
      long long x = qq[j].second;
      c[i][x] = dp[j];
    }
    f[i] = dp[m - 1];
    y[i] = qq[m - 1].first;
    id[i] = qq[m - 1].second;
  }
  for (long long i = 0; i < m; i++) {
    vector<pair<long long, long long> > qq;
    map<long long, long long> ss;
    set<long long> aa;
    set<long long>::iterator it;
    for (long long j = 0; j < n; j++) {
      qq.push_back({a[j][i], j});
      aa.insert(a[j][i]);
    }
    long long k = 0;
    for (it = aa.begin(); it != aa.end(); it++) {
      ss[*it] = k;
      k++;
    }
    for (long long j = 0; j < n; j++) {
      h1[j][i] = ss[a[j][i]];
    }
    sort(qq.begin(), qq.end());
    for (long long j = 0; j < n; j++) dp[i] = 0;
    dp[0] = 1;
    long long x = qq[0].second;
    d[x][i] = dp[0];
    for (long long j = 1; j < n; j++) {
      dp[j] = dp[j - 1];
      if (qq[j].first > qq[j - 1].first) dp[j]++;
      long long x = qq[j].second;
      d[x][i] = dp[j];
    }
    g[i] = dp[n - 1];
    s[i] = qq[n - 1].first;
    id1[i] = qq[n - 1].second;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      long long mx = max(f[i], g[j]);
      if (s[j] > a[i][j]) mx = max(mx, c[i][j] + h1[id1[j]][j] - h1[i][j]);
      if (y[i] > a[i][j]) mx = max(mx, d[i][j] + h[i][id[i]] - h[i][j]);
      cout << mx << " ";
    }
    cout << "\n";
  }
  return 0;
}
