#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
int R[1010][1010], C[1010][1010];
int RL[1010], CL[1010];
int main() {
  int n, m;
  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] = 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 Lb, Rb;
      auto row = equal_range(R[i] + 1, R[i] + RL[i] + 1, a[i][j]);
      auto col = equal_range(C[j] + 1, C[j] + CL[j] + 1, a[i][j]);
      Lb = max(row.first - R[i] - 1, col.first - C[j] - 1);
      Rb = max(R[i] + RL[i] - row.second, C[j] + CL[j] - col.second) + 1;
      printf("%d%c", Lb + 1 + Rb, j == m ? '\n' : ' ');
    }
  }
  return 0;
}
