#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e5 + 7;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, m;
vector<int> ve;
int a[1500][1500];
vector<int> h[1500];
vector<int> l[1500];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      h[i].push_back(a[i][j]);
      l[j].push_back(a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(h[i].begin(), h[i].end());
    h[i].erase(unique(h[i].begin(), h[i].end()), h[i].end());
  }
  for (int i = 1; i <= m; i++) {
    sort(l[i].begin(), l[i].end());
    l[i].erase(unique(l[i].begin(), l[i].end()), l[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int A = h[i].size(), aa = lower_bound(h[i].begin(), h[i].end(), a[i][j]) -
                                h[i].begin() + 1;
      int B = l[j].size(),
          b = lower_bound(l[j].begin(), l[j].end(), a[i][j]) - l[j].begin() + 1;
      cout << (aa < b ? max(B, b + A - aa) : max(A, aa + B - b)) << " ";
    }
    cout << endl;
  }
  return 0;
}
