#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int N = 1e3 + 10;
int mp[N][N];
int top1[N];
int top2[N];
int a[N][N];
int b[N][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", &mp[i][j]);
      a[i][j] = mp[i][j];
      b[j][i] = mp[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(a[i] + 1, a[i] + 1 + m);
    top1[i] = unique(a[i] + 1, a[i] + 1 + m) - a[i] - 1;
  }
  for (int i = 1; i <= m; i++) {
    sort(b[i] + 1, b[i] + 1 + n);
    top2[i] = unique(b[i] + 1, b[i] + 1 + n) - b[i] - 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int k1 = lower_bound(a[i] + 1, a[i] + 1 + top1[i], mp[i][j]) - a[i];
      int k2 = lower_bound(b[j] + 1, b[j] + 1 + top2[j], mp[i][j]) - b[j];
      int ans = max(k1, k2) + max(top1[i] - k1, top2[j] - k2);
      printf("%d ", ans);
    }
    printf("\n");
  }
  return 0;
}
