#include <bits/stdc++.h>
using namespace std;
void input(int n, int a[]) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
long long bin_expo(long long A, long long B, long long M) {
  long long res = 1LL;
  while (B > 0) {
    if (B % 2 == 1) {
      res = (res * A) % M;
    }
    A = (A * A) % M;
    B = B / 2;
  }
  return res;
}
int c = 1;
int main() {
  c++;
  long long n, m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long a[n][m];
  map<long long, vector<long long> > make_pair, mp2;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) scanf("%lld", &a[i][j]);
  int f = 1;
  c++;
  vector<long long> cc2;
  set<long long> v;
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) v.insert(a[j][i]);
    for (auto k : v) cc2.push_back(k);
    c++;
    mp2[i] = cc2;
    cc2.clear();
    v.clear();
  }
  for (long long i = 0; i < n; i++) {
    f = 1;
    for (long long j = 0; j < m; j++) v.insert(a[i][j]);
    for (auto k : v) cc2.push_back(k);
    c++;
    make_pair[i] = cc2;
    cc2.clear();
    v.clear();
  }
  c++;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      f = 1;
      long long ar = a[i][j];
      long long t1 = upper_bound(make_pair[i].begin(), make_pair[i].end(), ar) -
                     make_pair[i].begin();
      c++;
      long long t2 =
          upper_bound(mp2[j].begin(), mp2[j].end(), ar) - mp2[j].begin();
      int a1 = make_pair[i].size();
      int a2 = mp2[j].size();
      long long ans = max(t1, t2) + max(a1 - t1, a2 - t2);
      printf("%lld ", ans);
    }
    printf("\n");
  }
  long long ans = 0;
  if (f == 9) cout << ans - 1 << endl;
  return 0;
}
