#include <bits/stdc++.h>
using namespace std;
int ans[1001][1001], sum[1001][1001], a[1001][1001], n, m, tot, qwq, maxh[1001],
    maxl[1001];
struct asdf {
  int t, s;
} o[1001];
bool cmp(asdf a, asdf b) { return a.s < b.s; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; ++i) {
    tot = 0;
    for (int j = 1; j <= m; ++j) o[j].s = a[i][j], o[j].t = j;
    sort(o + 1, o + 1 + m, cmp);
    for (int j = 1; j <= m; ++j)
      if (o[j].s == o[j - 1].s)
        ans[i][o[j].t] = tot;
      else
        ans[i][o[j].t] = (++tot);
    maxh[i] = tot;
  }
  for (int j = 1; j <= m; ++j) {
    tot = 0;
    for (int i = 1; i <= n; ++i) o[i].s = a[i][j], o[i].t = i;
    sort(o + 1, o + 1 + n, cmp);
    for (int i = 1; i <= n; ++i)
      if (o[i].s == o[i - 1].s)
        sum[o[i].t][j] = tot;
      else
        sum[o[i].t][j] = (++tot);
    maxl[j] = tot;
  }
  for (int i = 1; i <= n; ++i, printf("\n"))
    for (int j = 1; j <= m; ++j)
      if (ans[i][j] > sum[i][j])
        printf("%d ", max(maxh[i], maxl[j] + ans[i][j] - sum[i][j]));
      else
        printf("%d ", max(maxl[j], maxh[i] + sum[i][j] - ans[i][j]));
}
