#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ss(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> ss[i][j];
  vector<int> rmx(n, 0), cmx(m, 0);
  vector<vector<int>> rc, cc;
  rc = cc = ss;
  for (int i = 0; i < n; ++i) {
    vector<pair<int, int>> v;
    for (int j = 0; j < m; ++j) v.push_back(make_pair(ss[i][j], j));
    sort(v.begin(), v.end());
    int c = 1;
    rc[i][v[0].second] = 1;
    for (int j = 1; j < m; ++j) {
      if (v[j].first != v[j - 1].first) c++;
      rc[i][v[j].second] = c;
    }
    rmx[i] = c;
  }
  for (int i = 0; i < m; ++i) {
    vector<pair<int, int>> v;
    for (int j = 0; j < n; ++j) v.push_back(make_pair(ss[j][i], j));
    sort(v.begin(), v.end());
    int c = 1;
    cc[v[0].second][i] = 1;
    for (int j = 1; j < n; ++j) {
      if (v[j].first != v[j - 1].first) c++;
      cc[v[j].second][i] = c;
    }
    cmx[i] = c;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int mx1 = (rc[i][j] < cc[i][j] ? cc[i][j] - rc[i][j] : 0) + rmx[i];
      int mx2 = (cc[i][j] < rc[i][j] ? rc[i][j] - cc[i][j] : 0) + cmx[j];
      int mx = ((mx1 > mx2) ? (mx1) : (mx2));
      cout << mx << " ";
    }
    cout << endl;
  }
  return 0;
}
