#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<int> vr[N], vc[N];
set<int> str[N], stc[N];
int a[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      str[i].insert(a[i][j]);
      stc[j].insert(a[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (auto j : str[i]) {
      vr[i].push_back(j);
    }
  }
  for (int i = 0; i < m; i++) {
    for (auto j : stc[i]) {
      vc[i].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int idxr =
          lower_bound(vr[i].begin(), vr[i].end(), a[i][j]) - vr[i].begin() + 1;
      int idxc =
          lower_bound(vc[j].begin(), vc[j].end(), a[i][j]) - vc[j].begin() + 1;
      int idx = max(idxr, idxc);
      int zr = (int)vr[i].size() - idxr;
      int zc = (int)vc[j].size() - idxc;
      cout << idx + max(zr, zc) << ' ';
    }
    cout << '\n';
  }
  return 0;
}
