#include <bits/stdc++.h>
using namespace std;
int binS(int x, vector<int> arr) {
  int l = 0, r = arr.size() - 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (arr[mid] == x)
      return mid;
    else if (arr[mid] < x) {
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return -1;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(m));
  vector<vector<int> > rows(n, vector<int>(m)), cols(m, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      rows[i][j] = a[i][j];
      cols[j][i] = a[i][j];
    }
  }
  vector<vector<int> > rowSet(n), colSet(m);
  for (int i = 0; i < n; i++) sort(rows[i].begin(), rows[i].end());
  for (int i = 0; i < m; i++) sort(cols[i].begin(), cols[i].end());
  for (int i = 0; i < n; i++) rowSet[i].push_back(rows[i][0]);
  for (int i = 0; i < m; i++) colSet[i].push_back(cols[i][0]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (rows[i][j] != rowSet[i].back()) rowSet[i].push_back(rows[i][j]);
      if (cols[j][i] != colSet[j].back()) colSet[j].push_back(cols[j][i]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ind1 = binS(a[i][j], rowSet[i]);
      int ind2 = binS(a[i][j], colSet[j]);
      cout << max(ind1, ind2) + max((int)rowSet[i].size() - ind1,
                                    (int)colSet[j].size() - ind2)
           << " ";
    }
    cout << "\n";
  }
}
int main(void) {
  cin.tie(0), cout.tie(0)->sync_with_stdio(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
