#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 3e5 + 5;
const int K = (1 << 17) + 10;
const long long int INF = 2e18 + 500;
const int inf = 0x7fffffff;
const int SQRT = 500;
const int lgN = 20;
int maxCol[1002], maxRow[1002];
int posRow[1002][1002], posCol[1002][1002];
int A[1002][1002];
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    vector<pair<int, int> > R(m);
    for (int j = 1; j <= m; j++) {
      cin >> A[i][j];
      R.push_back({A[i][j], j});
    }
    sort((R).begin(), (R).end());
    int idx = 0, prev = 0;
    for (auto v : R) {
      if (v.first != prev) {
        idx++;
        prev = v.first;
      }
      posRow[i][v.second] = idx;
    }
    maxRow[i] = idx;
  }
  for (int j = 1; j <= m; j++) {
    vector<pair<int, int> > C(m);
    for (int i = 1; i <= n; i++) {
      C.push_back({A[i][j], i});
    }
    sort((C).begin(), (C).end());
    int idx = 0, prev = 0;
    for (auto v : C) {
      if (v.first != prev) {
        idx++;
        prev = v.first;
      }
      posCol[j][v.second] = idx;
    }
    maxCol[j] = idx;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int rp = posRow[i][j], cp = posCol[j][i];
      if (rp == cp) {
        cout << max(maxRow[i], maxCol[j]) << " ";
      } else if (rp > cp) {
        int diff = rp - cp;
        cout << max(maxRow[i], maxCol[j] + diff) << " ";
      } else {
        int diff = cp - rp;
        cout << max(maxRow[i] + diff, maxCol[j]) << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
