#include <bits/stdc++.h>
using namespace std;
const int INFL = (int)1e9;
const long long INFLL = (long long)1e18;
long long Min(long long a, long long b) { return (a < b) ? a : b; }
long long Max(long long a, long long b) { return (a > b) ? a : b; }
long long gcd(long long m, long long n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}
long long lcm(long long m, long long n) { return m * n / gcd(m, n); }
long long a[1004][1004], rank1[1004][1004], rank2[1004][1004];
long long ggr1[1004], ggr2[1004];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
int main() {
  long long n, m, k, r;
  scanf("%lld %lld", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%lld", &a[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      q.push({a[i][j], j});
    }
    long long mx = 0, r = 1;
    while (!q.empty()) {
      if (q.top().first == mx) {
        rank1[i][q.top().second] = --r;
      } else
        rank1[i][q.top().second] = r;
      mx = q.top().first;
      r++;
      q.pop();
    }
    ggr1[i] = r - 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      q.push({a[j][i], j});
    }
    long long mx = 0, r = 1;
    while (!q.empty()) {
      if (q.top().first == mx) {
        rank2[q.top().second][i] = --r;
      } else {
        rank2[q.top().second][i] = r;
      }
      mx = q.top().first;
      r++;
      q.pop();
    }
    ggr2[i] = r - 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long mmx = 0;
      if (rank1[i][j] > rank2[i][j]) {
        mmx = ggr2[j] + rank1[i][j] - rank2[i][j];
        mmx = Max(mmx, ggr1[i]);
        printf("%lld ", Max(ggr1[i], ggr2[j] + rank1[i][j] - rank2[i][j]));
      } else {
        printf("%lld ", Max(ggr2[j], ggr1[i] + rank2[i][j] - rank1[i][j]));
      }
    }
    printf("\n");
  }
  return 0;
}
