#include <bits/stdc++.h>
const int maxn = 1e6;
int n, m;
inline int trans(int i, int t, int k) { return t ? i * m + k : k * m + i; }
struct solver {
  int l, epl, f[maxn], d[maxn], cp[maxn];
  struct edge {
    int v;
    edge *n;
  } ep[maxn * 2], *el[maxn];
  void uni(int u, int v) { f[get(u)] = get(v); }
  int get(int u) {
    if (f[u] != u) f[u] = get(f[u]);
    return f[u];
  }
  void init() {
    l = n * m;
    for (int i = 0; i < l; ++i) f[i] = i;
  }
  void add(int u, int v) {
    u = get(u);
    v = get(v);
    el[u] = &(ep[epl++] = {v, el[u]});
    ++d[v];
  }
  void sort() {
    std::queue<int> q;
    for (int i = 0; i < l; ++i)
      if (!d[i]) {
        cp[i] = 1;
        q.push(i);
      }
    int u;
    while (!q.empty()) {
      u = q.front();
      q.pop();
      for (edge *e = el[u]; e; e = e->n) {
        --d[e->v];
        cp[e->v] = std::max(cp[e->v], cp[u] + 1);
        if (!d[e->v]) q.push(e->v);
      }
    }
  }
} sm;
struct sorter {
  int t, k;
  std::vector<int> a, b;
  struct cmp {
    std::vector<int> &_a;
    bool operator()(const int &i, const int &j) const { return _a[i] > _a[j]; }
  };
  void add(int i, int j) { a[i] = j; }
  void sort() {
    for (int i = 0; i < a.size(); ++i) b[i] = i;
    std::sort(b.begin(), b.end(), cmp({a}));
  }
  void uniPoints(solver &s) {
    for (int i = 1; i < b.size(); ++i)
      if (a[b[i]] == a[b[i - 1]])
        s.uni(trans(b[i], t, k), trans(b[i - 1], t, k));
  }
  void setEdges(solver &s) {
    for (int i = 1; i < b.size(); ++i)
      if (a[b[i]] != a[b[i - 1]])
        s.add(trans(b[i], t, k), trans(b[i - 1], t, k));
  }
} p[maxn], q[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    q[i].t = 1;
    q[i].k = i;
    q[i].a.resize(n);
    q[i].b.resize(n);
  }
  for (int i = 0; i < n; ++i) {
    p[i].k = i;
    p[i].a.resize(m);
    p[i].b.resize(m);
  }
  sm.init();
  for (int i = 0, a; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a);
      p[i].add(j, a);
      q[j].add(i, a);
    }
  for (int i = 0; i < m; ++i) {
    q[i].sort();
    q[i].uniPoints(sm);
  }
  for (int i = 0; i < n; ++i) {
    p[i].sort();
    p[i].uniPoints(sm);
  }
  for (int i = 0; i < m; ++i) q[i].setEdges(sm);
  for (int i = 0; i < n; ++i) p[i].setEdges(sm);
  sm.sort();
  for (int i = 0; i < n; ++i) {
    printf("%d", sm.cp[sm.get(i * m)]);
    for (int j = 1; j < m; ++j) printf(" %d", sm.cp[sm.get(i * m + j)]);
    putchar('\n');
  }
  return 0;
}
