#include <bits/stdc++.h>
using namespace std;
int n, m, o[1010][1010], a[1010][1010], b[1010][1010], siza[1010], sizb[1010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &o[i][j]);
      a[i][j] = b[j][i] = o[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    sort(a[i], a[i] + m);
    siza[i] = unique(a[i], a[i] + m) - a[i];
  }
  for (int i = 0; i < m; i++) {
    sort(b[i], b[i] + n);
    sizb[i] = unique(b[i], b[i] + n) - b[i];
  }
  int x, y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      x = lower_bound(a[i], a[i] + siza[i], o[i][j]) - a[i];
      y = lower_bound(b[j], b[j] + sizb[j], o[i][j]) - b[j];
      printf("%d ", max(x, y) + max(siza[i] - x, sizb[j] - y));
    }
    putchar('\n');
  }
  return 0;
}
