#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, mp[1010][1010];
vector<int> l[1010], r[1010];
int ans[1010][1010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mp[i][j];
      l[i].push_back(mp[i][j]);
      r[j].push_back(mp[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(l[i].begin(), l[i].end());
    l[i].erase(unique(l[i].begin(), l[i].end()), l[i].end());
  }
  for (int j = 1; j <= m; j++) {
    sort(r[j].begin(), r[j].end());
    r[j].erase(unique(r[j].begin(), r[j].end()), r[j].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int t = mp[i][j], ml = l[i].size(), mr = r[j].size();
      int llow = lower_bound(l[i].begin(), l[i].end(), t) - l[i].begin() + 1;
      int rlow = lower_bound(r[j].begin(), r[j].end(), t) - r[j].begin() + 1;
      if (llow >= rlow)
        mr = llow - rlow + mr;
      else
        ml = rlow - llow + ml;
      ans[i][j] = max(mr, ml);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << ans[i][j] << " ";
    cout << endl;
  }
  return 0;
}
