#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int> > > a(n, vector<pair<int, int> >(m));
  vector<vector<pair<int, int> > > b(m, vector<pair<int, int> >(n));
  vector<vector<int> > na(n, vector<int>(m)), nb(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      a[i][j] = {x, j};
      b[j][i] = {x, i};
    }
  }
  vector<int> maxa(n), maxb(m);
  for (int i = 0; i < n; i++) {
    sort(a[i].begin(), a[i].end());
    int ord = 1;
    for (int j = 0; j < m; j++) {
      if (j > 0 and a[i][j - 1].first < a[i][j].first) ord++;
      na[i][a[i][j].second] = ord;
    }
    maxa[i] = ord;
  }
  for (int j = 0; j < m; j++) {
    sort(b[j].begin(), b[j].end());
    int ord = 1;
    for (int i = 0; i < n; i++) {
      if (i > 0 and b[j][i - 1].first < b[j][i].first) ord++;
      nb[b[j][i].second][j] = ord;
    }
    maxb[j] = ord;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int sol;
      if (nb[i][j] > na[i][j]) {
        sol = max(maxb[j], maxa[i] + nb[i][j] - na[i][j]);
      } else
        sol = max(maxa[i], maxb[j] - nb[i][j] + na[i][j]);
      cout << sol << " ";
    }
    cout << endl;
  }
}
