#include <bits/stdc++.h>
using namespace std;
const long long int N = 5010;
vector<long long int> func(vector<long long int> ar) {
  long long int n = ar.size();
  vector<pair<long long int, long long int> > ch(n);
  for (long long int i = 0; i < n; ++i) {
    ch[i].first = ar[i];
    ch[i].second = i;
  }
  sort(ch.begin(), ch.end());
  long long int num = 1;
  vector<pair<long long int, long long int> > ans(n);
  for (long long int i = 0; i < n; ++i) {
    ans[i].first = ch[i].second;
    if (i == 0) {
      ans[i].second = num;
    } else {
      if (ch[i].first != ch[i - 1].first) {
        ++num;
      }
      ans[i].second = num;
    }
  }
  sort(ans.begin(), ans.end());
  vector<long long int> lol;
  for (long long int i = 0; i < n; ++i) {
    lol.push_back(ans[i].second);
  }
  return lol;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long int ar[n][m];
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      cin >> ar[i][j];
    }
  }
  vector<vector<long long int> > rows(n);
  vector<long long int> maxrow(n);
  for (long long int i = 0; i < n; ++i) {
    vector<long long int> lol(m);
    for (long long int j = 0; j < m; ++j) {
      lol[j] = ar[i][j];
    }
    rows[i] = func(lol);
    maxrow[i] = 0;
    for (long long int j = 0; j < m; ++j) {
      maxrow[i] = max(maxrow[i], rows[i][j]);
    }
  }
  vector<vector<long long int> > cols(n);
  vector<long long int> maxcol(m);
  for (long long int j = 0; j < m; ++j) {
    vector<long long int> lol(n);
    for (long long int i = 0; i < n; ++i) {
      lol[i] = ar[i][j];
    }
    lol = func(lol);
    maxcol[j] = 0;
    for (long long int i = 0; i < n; ++i) {
      maxcol[j] = max(maxcol[j], lol[i]);
      cols[i].push_back(lol[i]);
    }
  }
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; ++j) {
      if (rows[i][j] == cols[i][j]) {
        cout << max(maxrow[i], maxcol[j]) << " ";
      } else if (rows[i][j] > cols[i][j]) {
        long long int diff = rows[i][j] - cols[i][j];
        cout << max(maxrow[i], maxcol[j] + diff) << " ";
      } else {
        long long int diff = cols[i][j] - rows[i][j];
        cout << max(maxrow[i] + diff, maxcol[j]) << " ";
      }
    }
    cout << endl;
  }
  return (0);
}
