#include <bits/stdc++.h>
using namespace std;
int n, m, a[1010][1010];
int rmax[1010], cmax[1010], r[1010][1010], c[1010][1010], ridx[1010][1010],
    cidx[1010][1010];
void init() {
  for (int i = 1; i <= n; i++) {
    memcpy(r[i], a[i], sizeof(r[i]));
    sort(r[i] + 1, r[i] + 1 + m);
    rmax[i] = unique(r[i] + 1, r[i] + 1 + m) - (r[i] + 1);
    for (int j = 1; j <= m; j++)
      ridx[i][j] = lower_bound(r[i] + 1, r[i] + rmax[i] + 1, a[i][j]) - r[i];
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) c[j][i] = a[i][j];
    sort(c[j] + 1, c[j] + n + 1);
    cmax[j] = unique(c[j] + 1, c[j] + n + 1) - (c[j] + 1);
    for (int i = 1; i <= n; i++)
      cidx[i][j] = lower_bound(c[j] + 1, c[j] + 1 + cmax[j], a[i][j]) - c[j];
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (ridx[i][j] > cidx[i][j]) {
        printf("%d ", max(rmax[i], cmax[j] + ridx[i][j] - cidx[i][j]));
      } else if (ridx[i][j] <= cidx[i][j]) {
        printf("%d ", max(cmax[j], rmax[i] + cidx[i][j] - ridx[i][j]));
      }
    }
    puts("");
  }
  return 0;
}
