#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& num) {
  char CH;
  bool F = false;
  for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
    ;
  for (num = 0; CH >= '0' && CH <= '9';
       num = num * 10 + CH - '0', CH = getchar())
    ;
  F && (num = -num);
}
int stk[70], tp;
template <class T>
inline void print(T p) {
  if (!p) {
    puts("0");
    return;
  }
  while (p) stk[++tp] = p % 10, p /= 10;
  while (tp) putchar(stk[tp--] + '0');
  putchar('\n');
}
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const int inf = 1e9;
const int N = 1e6 + 120;
const int maxn = 210;
const double eps = 1e-12;
int n, m, a[N], p[N], l[N], r[N], vis[N], ans[N];
vector<int> ve[N];
struct node {
  int a, id, i, j;
} po[N];
int cmp1(node x, node y) {
  if (x.a == y.a) return x.i < y.i;
  return x.a < y.a;
}
int cmp2(node x, node y) {
  if (x.a == y.a) return x.j < y.j;
  return x.a < y.a;
}
int findset(int x) {
  if (p[x] == x) return x;
  return p[x] = findset(p[x]);
}
int same(int x, int y) {
  int fx = findset(x), fy = findset(y);
  if (fx < fy)
    p[fy] = fx;
  else if (fx > fy)
    p[fx] = fy;
}
int main() {
  int cnt = 0;
  read(n);
  read(m);
  for (int i = 0; i <= n * m; i++) p[i] = i;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cnt++;
      po[cnt].id = cnt;
      po[cnt].i = i;
      po[cnt].j = j;
      read(po[cnt].a);
    }
  }
  sort(po + 1, po + cnt + 1, cmp2);
  for (int i = 2; i <= cnt; i++) {
    if (po[i].a == po[i - 1].a && po[i].j == po[i - 1].j)
      same(po[i].id, po[i - 1].id);
  }
  sort(po + 1, po + cnt + 1, cmp1);
  for (int i = 2; i <= cnt; i++) {
    if (po[i].a == po[i - 1].a && po[i].i == po[i - 1].i)
      same(po[i].id, po[i - 1].id);
  }
  for (int i = 1; i <= cnt; i++) {
    int root = findset(po[i].id);
    ve[root].push_back(i);
  }
  for (int i = 1; i <= cnt; i++) {
    int root = findset(po[i].id);
    if (!vis[root]) {
      int temp = 0, len = ve[root].size();
      for (int j = 0; j < len; j++) {
        int x = ve[root][j];
        temp = max(temp, r[po[x].i]);
        temp = max(temp, l[po[x].j]);
      }
      temp++;
      ans[root] = temp;
      for (int j = 0; j < len; j++) {
        int x = ve[root][j];
        l[po[x].j] = r[po[x].i] = temp;
      }
      vis[root] = 1;
    }
    ans[po[i].id] = ans[root];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m - 1; j++) printf("%d ", ans[(i - 1) * m + j]);
    printf("%d\n", ans[i * m]);
  }
  return 0;
}
