#include <bits/stdc++.h>
using namespace std;
const int N(1009);
int n, m, ans;
int a[N][N];
int b[N], c[N];
struct A {
  int val, id;
} tmp[N];
struct B {
  int val[N];
  int maxv;
} row[N], col[N];
bool cmp(A x, A y) { return x.val < y.val; }
void calc_row(int x) {
  for (int i = 1; i <= m; i++) {
    tmp[i].val = a[x][i];
    tmp[i].id = i;
  }
  sort(tmp + 1, tmp + m + 1, cmp);
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (tmp[i].val == tmp[i - 1].val) {
      c[tmp[i].id] = c[tmp[i - 1].id];
    } else {
      c[tmp[i].id] = ++cnt;
    }
  }
  for (int i = 1; i <= m; i++) {
    row[x].val[i] = c[i];
  }
  row[x].maxv = cnt;
}
void calc_col(int y) {
  for (int i = 1; i <= n; i++) {
    tmp[i].val = a[i][y];
    tmp[i].id = i;
  }
  sort(tmp + 1, tmp + n + 1, cmp);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (tmp[i].val == tmp[i - 1].val) {
      c[tmp[i].id] = c[tmp[i - 1].id];
    } else {
      c[tmp[i].id] = ++cnt;
    }
  }
  for (int i = 1; i <= n; i++) {
    col[y].val[i] = c[i];
  }
  col[y].maxv = cnt;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    calc_row(i);
  }
  for (int i = 1; i <= m; i++) {
    calc_col(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int tmp = row[i].val[j] - col[j].val[i];
      if (tmp < 0) {
        cout << max(col[j].maxv, row[i].maxv - tmp) << ' ';
      } else {
        cout << max(row[i].maxv, col[j].maxv + tmp) << ' ';
      }
    }
    cout << endl;
  }
  return 0;
}
