#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n, m;
int a[1005][1005];
int l[1005], c[1005], l1[1005], c1[1005];
int a1[1005][1005];
int a2[1005][1005];
set<int> lin, col;
vector<int> V;
vector<pair<int, int> > v[1000005];
map<int, int> f;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &a[i][j]);
      V.push_back(a[i][j]);
    }
  }
  sort(V.begin(), V.end());
  unique(V.begin(), V.end());
  int NR = 0;
  for (auto it : V) f[it] = ++NR;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      a[i][j] = f[a[i][j]];
      v[a[i][j]].push_back({i, j});
    }
  }
  for (int i = 1; i <= NR; ++i) {
    lin.clear();
    col.clear();
    for (auto it : v[i]) {
      lin.insert(it.first);
      col.insert(it.second);
      a1[it.first][it.second] = max(l[it.first], c[it.second]);
    }
    for (auto it : lin) ++l[it];
    for (auto it : col) ++c[it];
  }
  for (int i = NR; i >= 1; --i) {
    lin.clear();
    col.clear();
    for (auto it : v[i]) {
      lin.insert(it.first);
      col.insert(it.second);
      a2[it.first][it.second] = max(l1[it.first], c1[it.second]);
    }
    for (auto it : lin) ++l1[it];
    for (auto it : col) ++c1[it];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) printf("%d ", a1[i][j] + a2[i][j] + 1);
    printf("\n");
  }
  return 0;
}
