#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long double INF = (long double)10000000000000;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
int n, m;
int a[1000][1000];
vector<int> vx[1000], vy[1000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      vx[i].push_back(a[i][j]);
    }
    sort(vx[i].begin(), vx[i].end());
    int len = unique(vx[i].begin(), vx[i].end()) - vx[i].begin();
    vx[i].erase(vx[i].begin() + len, vx[i].end());
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      vy[i].push_back(a[j][i]);
    }
    sort(vy[i].begin(), vy[i].end());
    int len = unique(vy[i].begin(), vy[i].end()) - vy[i].begin();
    vy[i].erase(vy[i].begin() + len, vy[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0) cout << " ";
      int idx =
          lower_bound(vx[i].begin(), vx[i].end(), a[i][j]) - vx[i].begin();
      int idy =
          lower_bound(vy[j].begin(), vy[j].end(), a[i][j]) - vy[j].begin();
      int ans1 = mod, ans2 = mod;
      if (idx >= idy)
        ans1 = max(idx + (int)vy[j].size() - idy, (int)vx[i].size());
      if (idx <= idy)
        ans2 = max(idy + (int)vx[i].size() - idx, (int)vy[j].size());
      cout << min(ans1, ans2);
    }
    cout << endl;
  }
  return 0;
}
