#include <bits/stdc++.h>
using namespace std;
int F() {
  char ch;
  int x, a;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-')
    ch = getchar(), a = -1;
  else
    a = 1;
  x = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0';
  return a * x;
}
int n, m;
int a[1010][1010];
int uni[2333333], unt;
vector<pair<int, int> > c[2333333];
int g[1010], f[1010];
int b[1010][1010];
int main() {
  (((n) = F()), ((m) = F()));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) ((a[i][j]) = F()), uni[++unt] = a[i][j];
  sort(uni + 1, uni + unt + 1);
  unt = unique(uni + 1, uni + unt + 1) - uni - 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      a[i][j] = lower_bound(uni + 1, uni + unt + 1, a[i][j]) - uni;
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      c[a[i][j]].push_back(make_pair(i, j));
    }
  for (int i = 1; i <= unt; ++i) {
    for (auto v : c[i]) {
      int x = v.first, y = v.second;
      a[x][y] = max(f[x], g[y]) + 1;
    }
    vector<int> X, Y;
    for (auto v : c[i]) {
      int x = v.first, y = v.second;
      X.push_back(x);
      Y.push_back(y);
    }
    sort((X).begin(), (X).end());
    sort((Y).begin(), (Y).end());
    vector<int>::iterator itx = unique((X).begin(), (X).end()),
                          ity = unique((Y).begin(), (Y).end());
    X.erase(itx, X.end());
    Y.erase(ity, Y.end());
    for (auto x : X) ++f[x];
    for (auto y : Y) ++g[y];
  }
  memset(f, 0, sizeof f);
  memset(g, 0, sizeof g);
  for (int i = unt; i; --i) {
    for (auto v : c[i]) {
      int x = v.first, y = v.second;
      b[x][y] = max(f[x], g[y]) + 1;
    }
    vector<int> X, Y;
    for (auto v : c[i]) {
      int x = v.first, y = v.second;
      X.push_back(x), Y.push_back(y);
    }
    sort((X).begin(), (X).end());
    sort((Y).begin(), (Y).end());
    vector<int>::iterator itx = unique((X).begin(), (X).end()),
                          ity = unique((Y).begin(), (Y).end());
    X.erase(itx, X.end());
    Y.erase(ity, Y.end());
    for (auto x : X) ++f[x];
    for (auto y : Y) ++g[y];
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      printf("%d%c", a[i][j] + b[i][j] - 1, " \n"[j == m]);
}
