#include <bits/stdc++.h>
struct data {
  int v, lab;
} s[1500], mid;
struct data1 {
  int v1, v2, v;
} a[1005][1005];
int n, m, lo, k, cnt, h[1500], l[1500], b[1500][1500];
bool operator<(data a, data b) {
  if (a.v > b.v) return 1;
  return 0;
}
using namespace std;
priority_queue<data> q;
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].v);
      s[j].v = a[i][j].v;
      s[j].lab = j;
      q.push(s[j]);
    }
    cnt = 0;
    lo = 0;
    while (!q.empty()) {
      mid = q.top();
      q.pop();
      if (mid.v == a[i][lo].v)
        a[i][mid.lab].v1 = cnt;
      else
        a[i][mid.lab].v1 = ++cnt;
      lo = mid.lab;
    }
    h[i] = cnt;
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      s[i].lab = i;
      s[i].v = a[i][j].v;
      q.push(s[i]);
    }
    cnt = 0;
    lo = 0;
    while (!q.empty()) {
      mid = q.top();
      q.pop();
      if (mid.v == a[lo][j].v)
        a[mid.lab][j].v2 = cnt;
      else
        a[mid.lab][j].v2 = ++cnt;
      lo = mid.lab;
    }
    l[j] = cnt;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      k = a[i][j].v1 - a[i][j].v2;
      if (k > 0)
        b[i][j] = max(h[i], l[j] + k);
      else
        b[i][j] = max(h[i] - k, l[j]);
      printf("%d ", b[i][j]);
    }
    printf("\n");
  }
}
