#include <bits/stdc++.h>
using namespace std;
int mat[1234][1234], matb[1234][1234], matk[1234][1234], maxb[1234], maxk[1234];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, iter;
  vector<int> v;
  map<int, int> mp;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  for (int i = 0; i < n; i++) {
    v.clear();
    mp.clear();
    for (int j = 0; j < m; j++) v.push_back(mat[i][j]);
    sort(v.begin(), v.end());
    iter = 1;
    for (int j = 0; j < m; j++)
      if (mp[v[j]] == 0) mp[v[j]] = iter++;
    maxb[i] = iter - 1;
    for (int j = 0; j < m; j++) matb[i][j] = mp[mat[i][j]];
  }
  for (int i = 0; i < m; i++) {
    v.clear();
    mp.clear();
    for (int j = 0; j < n; j++) v.push_back(mat[j][i]);
    sort(v.begin(), v.end());
    iter = 1;
    for (int j = 0; j < n; j++)
      if (mp[v[j]] == 0) mp[v[j]] = iter++;
    maxk[i] = iter - 1;
    for (int j = 0; j < n; j++) matk[i][j] = mp[mat[j][i]];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j) cout << " ";
      int diff = abs(matb[i][j] - matk[j][i]);
      if (matb[i][j] > matk[j][i])
        cout << max(maxb[i], maxk[j] + diff);
      else
        cout << max(maxb[i] + diff, maxk[j]);
    }
    cout << endl;
  }
  return 0;
}
