#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, i, j, cnt, r_row, r_col, s_row, s_col;
  cin >> n >> m;
  set<long long> rows[n], cols[m];
  vector<vector<long long>> grid(n, vector<long long>(m, 0));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> grid[i][j];
      rows[i].insert(grid[i][j]);
      cols[j].insert(grid[i][j]);
    }
  }
  unordered_map<long long, long long> mp_row[n], mp_col[m];
  for (i = 0; i < n; i++) {
    cnt = 1;
    for (auto it : rows[i]) {
      mp_row[i][it] = cnt;
      cnt++;
    }
    mp_row[i][-1] = rows[i].size();
    rows[i].clear();
  }
  for (i = 0; i < m; i++) {
    cnt = 1;
    for (auto it : cols[i]) {
      mp_col[i][it] = cnt;
      cnt++;
    }
    mp_col[i][-1] = cols[i].size();
    cols[i].clear();
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      r_row = mp_row[i][grid[i][j]];
      r_col = mp_col[j][grid[i][j]];
      s_row = mp_row[i][-1];
      s_col = mp_col[j][-1];
      cout << (max(r_row, r_col) + max(s_row - r_row, s_col - r_col)) << " ";
    }
    cout << "\n";
  }
}
