#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1001][1001];
int b[1001][1001], c[1001][1001];
int l[1001], r[1001];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      c[j][i] = a[i][j];
      b[i][j] = a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(b[i] + 1, b[i] + m + 1);
    r[i] = unique(b[i] + 1, b[i] + 1 + m) - b[i] - 1;
  }
  for (int i = 1; i <= m; i++) {
    sort(c[i] + 1, c[i] + n + 1);
    l[i] = unique(c[i] + 1, c[i] + 1 + n) - c[i] - 1;
  }
  int x, y, num;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      x = lower_bound(b[i] + 1, b[i] + r[i] + 1, a[i][j]) - b[i];
      y = lower_bound(c[j] + 1, c[j] + l[j] + 1, a[i][j]) - c[j];
      num = max(x, y);
      num = max(num + r[i] - x, num + l[j] - y);
      printf(j == m ? "%d\n" : "%d ", num);
    }
  }
}
