#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<long long int> > v(n, vector<long long int>(m)), vr(n), vc(m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
      vr[i].push_back(v[i][j]);
      vc[j].push_back(v[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    sort(vr[i].begin(), vr[i].end());
    vr[i].erase(unique(vr[i].begin(), vr[i].end()), vr[i].end());
  }
  for (int i = 0; i < m; i++) {
    sort(vc[i].begin(), vc[i].end());
    vc[i].erase(unique(vc[i].begin(), vc[i].end()), vc[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long int lrow =
          lower_bound(vr[i].begin(), vr[i].end(), v[i][j]) - vr[i].begin();
      long long int lcol =
          lower_bound(vc[j].begin(), vc[j].end(), v[i][j]) - vc[j].begin();
      long long int f = max(lrow, lcol);
      cout << max(f + vr[i].size() - lrow, f + vc[j].size() - lcol) << " ";
    }
    cout << endl;
  }
  return 0;
}
