#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, m;
int a[N][N], r[N][N], c[N][N], rl[N], cl[N];
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]);
      r[i][j] = a[i][j];
      c[j][i] = a[i][j];
    }
  for (int i = 1; i <= n; i++) {
    sort(r[i] + 1, r[i] + m + 1);
    rl[i] = unique(r[i] + 1, r[i] + m + 1) - (r[i] + 1);
  }
  for (int j = 1; j <= m; j++) {
    sort(c[j] + 1, c[j] + n + 1);
    cl[j] = unique(c[j] + 1, c[j] + n + 1) - (c[j] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int ans = 1, tmp1, tmp2;
      tmp1 = lower_bound(r[i] + 1, r[i] + rl[i] + 1, a[i][j]) - r[i];
      tmp2 = lower_bound(c[j] + 1, c[j] + cl[j] + 1, a[i][j]) - c[j];
      ans += max(tmp1 - 1, tmp2 - 1);
      ans += max(rl[i] - tmp1, cl[j] - tmp2);
      printf("%d ", ans);
    }
    printf("\n");
  }
  return 0;
}
