#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1005][1005];
void solve() {
  map<int, int> row[1005], col[1005];
  for (long long i = 0; i < (n); ++i) {
    set<int> s;
    for (long long j = 0; j < (m); ++j) {
      s.insert(a[i][j]);
    }
    int c = 1;
    for (auto j : s) row[i][j] = c, c++;
  }
  for (long long j = 0; j < (m); ++j) {
    set<int> s;
    for (long long i = 0; i < (n); ++i) {
      s.insert(a[i][j]);
    }
    int c = 1;
    for (auto i : s) col[j][i] = c, c++;
  }
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      cout << max(row[i][a[i][j]], col[j][a[i][j]]) +
                  max(row[i].size() - row[i][a[i][j]],
                      col[j].size() - col[j][a[i][j]])
           << ' ';
    }
    cout << "\n";
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    cin >> n >> m;
    for (long long i = 0; i < (n); ++i)
      for (long long j = 0; j < (m); ++j) cin >> a[i][j];
    solve();
  }
}
