#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, m, j, x;
  cin >> n >> m;
  long long a[n][m], lowR[n][m], highR[n][m], lowC[n][m], highC[n][m];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) cin >> a[i][j];
  }
  for (i = 0; i < n; i++) {
    vector<long long> v, v1;
    for (j = 0; j < m; j++) {
      v.push_back(a[i][j]);
    }
    sort(v.begin(), v.end());
    v1.push_back(v[0]);
    for (j = 1; j < v.size(); j++) {
      if (v[j] != v[j - 1]) v1.push_back(v[j]);
    }
    for (j = 0; j < m; j++) {
      lowR[i][j] = lower_bound(v1.begin(), v1.end(), a[i][j]) - v1.begin();
      highR[i][j] = v1.size() - lowR[i][j] - 1;
    }
  }
  for (i = 0; i < m; i++) {
    vector<long long> v, v1;
    for (j = 0; j < n; j++) {
      v.push_back(a[j][i]);
    }
    sort(v.begin(), v.end());
    v1.push_back(v[0]);
    for (j = 1; j < v.size(); j++) {
      if (v[j] != v[j - 1]) v1.push_back(v[j]);
    }
    for (j = 0; j < n; j++) {
      lowC[j][i] = lower_bound(v1.begin(), v1.end(), a[j][i]) - v1.begin();
      highC[j][i] = v1.size() - lowC[j][i] - 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++)
      cout << max(lowR[i][j], lowC[i][j]) + max(highR[i][j], highC[i][j]) + 1
           << " ";
    cout << endl;
  }
  return 0;
}
