#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
map<int, int> mr[1200], mc[1200];
int a[1000][1000];
long long up[1000][1000];
long long down[1000][1000];
vector<int> row[1200];
vector<int> col[1200];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (mr[i][a[i][j]] == 0) {
        row[i].push_back(a[i][j]);
      }
      if (!(mc[j][a[i][j]])) {
        col[j].push_back(a[i][j]);
      }
      mr[i][a[i][j]]++;
      mc[j][a[i][j]]++;
    }
  }
  for (long long i = 0; i < max(n, m); i++) {
    sort(row[i].begin(), row[i].end());
    sort(col[i].begin(), col[i].end());
  }
  for (long long i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int les1 =
          lower_bound(row[i].begin(), row[i].end(), a[i][j]) - row[i].begin();
      int les2 =
          lower_bound(col[j].begin(), col[j].end(), a[i][j]) - col[j].begin();
      int biger1 = row[i].size() - les1;
      int biger2 = col[j].size() - les2;
      long long mx = max(les1, les2);
      long long mxx = max(biger1, biger2);
      cout << mx + mxx << " ";
    }
    cout << endl;
  }
}
