#include <bits/stdc++.h>
using namespace std;
long long mat[1005][1005], ans[1005][1005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, m;
    cin >> n >> m;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) cin >> mat[i][j];
    }
    vector<long long int> row[n], col[m];
    for (long long int i = 0; i < n; i++) {
      unordered_map<long long, long long> make_pair;
      for (long long int j = 0; j < m; j++) {
        if (make_pair.find(mat[i][j]) == make_pair.end()) {
          make_pair[mat[i][j]] = 1;
          row[i].push_back(mat[i][j]);
        }
      }
      sort((row[i]).begin(), (row[i]).end());
    }
    for (long long int i = 0; i < m; i++) {
      unordered_map<long long, long long> make_pair;
      for (long long int j = 0; j < n; j++) {
        if (make_pair.find(mat[j][i]) == make_pair.end()) {
          make_pair[mat[j][i]] = 1;
          col[i].push_back(mat[j][i]);
        }
      }
      sort((col[i]).begin(), (col[i]).end());
    }
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long id1 =
            lower_bound((row[i]).begin(), (row[i]).end(), mat[i][j]) -
            row[i].begin() + 1;
        long long id2 =
            lower_bound((col[j]).begin(), (col[j]).end(), mat[i][j]) -
            col[j].begin() + 1;
        if (id1 > id2) {
          ans[i][j] = id1 + max((long long int)row[i].size() - id1,
                                (long long int)col[j].size() - id2);
        } else
          ans[i][j] = id2 + max((long long int)row[i].size() - id1,
                                (long long int)col[j].size() - id2);
      }
    }
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) cout << ans[i][j] << " ";
      cout << "\n";
    }
  }
  return 0;
}
