#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int d[N];
int a[N][N], b[N][N], c[N][N], row[N], col[N];
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]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      d[j] = a[i][j];
    }
    sort(d + 1, d + m + 1);
    int k = unique(d + 1, d + m + 1) - d - 1;
    for (int j = 1; j <= m; j++)
      b[i][j] = lower_bound(d + 1, d + k + 1, a[i][j]) - d;
    row[i] = k;
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) d[i] = a[i][j];
    sort(d + 1, d + n + 1);
    int k = unique(d + 1, d + n + 1) - d - 1;
    for (int i = 1; i <= n; i++)
      c[i][j] = lower_bound(d + 1, d + k + 1, a[i][j]) - d;
    col[j] = k;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int ans = 0;
      if (b[i][j] >= c[i][j]) {
        ans = max(ans, row[i]);
        ans = max(ans, col[j] + b[i][j] - c[i][j]);
      } else {
        ans = max(ans, col[j]);
        ans = max(ans, row[i] + c[i][j] - b[i][j]);
      }
      printf("%d ", ans);
    }
    printf("\n");
  }
  return 0;
}
