#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
const long long N = 1e3 + 3;
long long a[N][N];
long long n, m;
vector<long long> row[N], col[N];
void settle(vector<long long>& v) {
  sort(v.begin(), v.end());
  for (long long i = 1; i < v.size(); i++) {
    if (v[i] == v[i - 1]) v[i - 1] = 1e10;
  }
  sort(v.begin(), v.end());
  while (v.back() == 1e10) v.pop_back();
}
long long get(vector<long long>& v, long long key) {
  return (lower_bound(v.begin(), v.end(), key) - v.begin());
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
      col[j].push_back(a[i][j]);
      row[i].push_back(a[i][j]);
    }
    settle(row[i]);
  }
  for (long long j = 1; j <= m; j++) settle(col[j]);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      long long posr = get(row[i], a[i][j]);
      long long posc = get(col[j], a[i][j]);
      long long x = row[i].size();
      long long y = col[j].size();
      if (posr >= posc) {
        cout << max(x, posr - posc + y) << ' ';
      } else {
        cout << max(y, posc - posr + x) << ' ';
      }
    }
    cout << '\n';
  }
  return 0;
}
