#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 8;
const long long maxn = 1e3 + 5;
const long long mo_num = 1e9 + 7;
long long n, m, a[maxn], b[maxn], ans;
long long g[maxn][maxn];
long long f[maxn][maxn];
set<long long> h[maxn], l[maxn];
unordered_map<long long, long long> H[maxn], L[maxn];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> g[i][j];
      h[i].insert(g[i][j]);
      l[j].insert(g[i][j]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    long long cnt = 0;
    for (auto j : h[i]) H[i][j] = ++cnt;
  }
  for (long long i = 1; i <= m; i++) {
    long long cnt = 0;
    for (auto j : l[i]) L[i][j] = ++cnt;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      long long val = g[i][j];
      long long hx = H[i][val] - 1;
      long long hd = H[i].size() - hx - 1;
      long long lx = L[j][val] - 1;
      long long ld = L[j].size() - lx - 1;
      cout << max(hx, lx) + 1 + max(hd, ld) << " ";
    }
    cout << '\n';
  }
  return 0;
}
