#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 3;
int a[maxn][maxn], b[maxn][maxn], c[maxn], d[maxn];
int e[maxn][maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      b[j][i] = a[i][j];
      e[i][j] = a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(a[i] + 1, a[i] + 1 + m);
    c[i] = unique(a[i] + 1, a[i] + m + 1) - (a[i] + 1);
  }
  for (int i = 1; i <= m; i++) {
    sort(b[i] + 1, b[i] + 1 + n);
    d[i] = unique(b[i] + 1, b[i] + n + 1) - (b[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int ta = lower_bound(a[i], a[i] + c[i], e[i][j]) - a[i];
      int tb = lower_bound(b[j], b[j] + d[j], e[i][j]) - b[j];
      cout << max(ta, tb) + max(c[i] - ta, d[j] - tb) << " ";
    }
    cout << endl;
  }
}
