#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 2e3 + 10, maxm = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
int casn, n, m, k;
int pz[maxn][maxn];
int c[maxn][maxn], h[maxn][maxn];
int cc[maxn], hh[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> pz[i][j];
  for (int i = 1; i <= n; ++i) {
    pair<int, int> p[maxn];
    for (int j = 1; j <= m; ++j) p[j] = make_pair(pz[i][j], j);
    sort(p + 1, p + 1 + m);
    int cnt = 0;
    for (int j = 1; j <= m; ++j) {
      if (p[j].first != p[j - 1].first) cnt++;
      c[i][p[j].second] = cnt;
    }
    cc[i] = cnt;
  }
  for (int i = 1; i <= m; ++i) {
    pair<int, int> p[maxn];
    for (int j = 1; j <= n; ++j) p[j] = make_pair(pz[j][i], j);
    sort(p + 1, p + 1 + n);
    int cnt = 0;
    for (int j = 1; j <= n; ++j) {
      if (p[j].first != p[j - 1].first) cnt++;
      h[p[j].second][i] = cnt;
    }
    hh[i] = cnt;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int a = max(h[i][j], c[i][j]);
      int b = max(cc[i] - c[i][j], hh[j] - h[i][j]);
      cout << a + b << ' ';
    }
    cout << '\n';
  }
  return 0;
}
