#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> maxr(n, 0), maxc(m, 0);
  vector<vector<long long int>> a(n, vector<long long int>(m, 0)),
      row(n, vector<long long int>(m, 0)), col(n, vector<long long int>(m, 0));
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++) cin >> a[i][j];
  for (long long int i = 0; i < n; i++) {
    long long int cnt = 0, prv = 0;
    set<pair<long long int, long long int>> s;
    for (long long int j = 0; j < m; j++) s.insert({a[i][j], j});
    while (!s.empty()) {
      pair<long long int, long long int> p = *s.begin();
      long long int val = p.first, idx = p.second;
      s.erase(p);
      if (val == prv)
        row[i][idx] = cnt;
      else
        row[i][idx] = ++cnt;
      prv = val;
    }
    for (long long int j = 0; j < m; j++) maxr[i] = max(maxr[i], row[i][j]);
  }
  for (long long int i = 0; i < m; i++) {
    long long int cnt = 0, prv = 0;
    set<pair<long long int, long long int>> s;
    for (long long int j = 0; j < n; j++) s.insert({a[j][i], j});
    while (!s.empty()) {
      pair<long long int, long long int> p = *s.begin();
      s.erase(p);
      long long int val = p.first, idx = p.second;
      if (val == prv)
        col[idx][i] = cnt;
      else
        col[idx][i] = ++cnt;
      prv = val;
    }
    for (long long int j = 0; j < n; j++) maxc[i] = max(maxc[i], col[j][i]);
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (row[i][j] >= col[i][j])
        cout << max(maxr[i], maxc[j] + abs(row[i][j] - col[i][j])) << ' ';
      else
        cout << max(maxc[j], maxr[i] + abs(row[i][j] - col[i][j])) << ' ';
    }
    cout << endl;
  }
}
