#include <bits/stdc++.h>
using namespace std;
map<long long, map<long long, long long> > chcl, chrw;
long long szcl[1002], szrw[1002], uncl[1002][1002], unrw[1002][1002],
    in[1002][1002];
long long clindx(long long i, long long x) {
  long long l, r, md;
  l = 1;
  r = szcl[i] + 1;
  while (r - l > 1) {
    md = (l + r) / 2;
    if (uncl[i][md] <= x)
      l = md;
    else
      r = md;
  }
  return l;
}
long long rwindx(long long i, long long x) {
  long long l, r, md;
  l = 1;
  r = szrw[i] + 1;
  while (r - l > 1) {
    md = (l + r) / 2;
    if (unrw[i][md] <= x)
      l = md;
    else
      r = md;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long int i, j, x, y, n, m, cnt = 0, k, g, flg, t, clid, rwid;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> in[i][j];
      if (!chcl[j][in[i][j]]) {
        chcl[j][in[i][j]]++;
        uncl[j][++szcl[j]] = in[i][j];
      }
      if (!chrw[i][in[i][j]]) {
        chrw[i][in[i][j]]++;
        unrw[i][++szrw[i]] = in[i][j];
      }
    }
  }
  for (i = 1; i <= n; i++) {
    sort(unrw[i] + 1, unrw[i] + 1 + szrw[i]);
  }
  for (i = 1; i <= m; i++) {
    sort(uncl[i] + 1, uncl[i] + 1 + szcl[i]);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      clid = clindx(j, in[i][j]);
      rwid = rwindx(i, in[i][j]);
      x = szrw[i];
      y = szcl[j];
      k = abs(clid - rwid);
      if (clid > rwid)
        x += k;
      else
        y += k;
      g = max(x, y);
      printf("%lld ", g);
    }
    printf("\n");
  }
}
