#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1);
int n, m;
int a[maxn][maxn];
typedef struct node {
  int pos;
  int val;
} NODE;
bool cmp(NODE a, NODE b) { return a.val < b.val; }
int hang[maxn];
int lie[maxn];
int h[maxn][maxn];
int l[maxn][maxn];
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]);
    }
  }
  NODE tmp[maxn];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      tmp[j].pos = j;
      tmp[j].val = a[i][j];
    }
    sort(tmp + 1, tmp + 1 + m, cmp);
    tmp[0].val = -1;
    int rat = 0;
    for (int j = 1; j <= m; j++) {
      if (tmp[j].val > tmp[j - 1].val) {
        rat++;
      }
      h[i][tmp[j].pos] = rat;
    }
    hang[i] = rat;
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      tmp[i].pos = i;
      tmp[i].val = a[i][j];
    }
    sort(tmp + 1, tmp + 1 + n, cmp);
    tmp[0].val = -1;
    int rat = 0;
    for (int i = 1; i <= n; i++) {
      if (tmp[i].val > tmp[i - 1].val) {
        rat++;
      }
      l[tmp[i].pos][j] = rat;
    }
    lie[j] = rat;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (h[i][j] >= l[i][j]) {
        printf("%d ", max(lie[j] - l[i][j] + h[i][j], hang[i]));
      } else {
        printf("%d ", max(hang[i] - h[i][j] + l[i][j], lie[j]));
      }
    }
    printf("\n");
  }
}
