#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
int root[MAX];
int find(int x) {
  if (root[x] == x) return x;
  return root[x] = find(root[x]);
}
void join(int x, int y) {
  x = find(x);
  y = find(y);
  root[x] = y;
}
int n, m;
set<int> G[MAX];
int val[MAX];
set<int> nodes;
int deg[MAX];
void solve() {
  for (int v : nodes) {
    for (int e : G[v]) {
      deg[e]++;
    }
  }
  queue<int> q;
  for (int v : nodes)
    if (deg[v] == 0) {
      val[v] = 1;
      q.push(v);
    }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int v : G[cur]) {
      val[v] = max(val[v], val[cur] + 1);
      deg[v]--;
      if (deg[v] == 0) {
        q.push(v);
      }
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      val[i * m + j] = max(1, val[find(i * m + j)]);
    }
}
int t_[MAX];
int T(int i, int j) { return t_[i * m + j]; }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) {
      scanf("%d", &t_[i * m + j]);
      root[i * m + j] = i * m + j;
    }
  {
    vector<int> idx;
    for (int i = 0; i < m; ++i) idx.push_back(i);
    for (int i = 0; i < n; ++i) {
      sort(idx.begin(), idx.end(), [&](int id1, int id2) {
        if (T(i, id1) != T(i, id2)) return T(i, id1) < T(i, id2);
        return id1 < id2;
      });
      for (int j = 0; j < m - 1; ++j) {
        if (T(i, idx[j]) == T(i, idx[j + 1])) {
          join(i * m + idx[j], i * m + idx[j + 1]);
        }
      }
    }
  }
  {
    vector<int> idy;
    for (int i = 0; i < n; ++i) idy.push_back(i);
    for (int j = 0; j < m; ++j) {
      sort(idy.begin(), idy.end(), [&](int id1, int id2) {
        if (T(id1, j) != T(id2, j)) return T(id1, j) < T(id2, j);
        return id1 < id2;
      });
      for (int i = 0; i < n - 1; ++i) {
        if (T(idy[i], j) == T(idy[i + 1], j)) {
          join(m * idy[i] + j, m * idy[i + 1] + j);
        }
      }
    }
  }
  {
    vector<int> idx;
    for (int i = 0; i < m; ++i) idx.push_back(i);
    for (int i = 0; i < n; ++i) {
      sort(idx.begin(), idx.end(), [&](int id1, int id2) {
        if (T(i, id1) != T(i, id2)) return T(i, id1) < T(i, id2);
        return id1 < id2;
      });
      for (int j = 0; j < m - 1; ++j) {
        if (T(i, idx[j]) != T(i, idx[j + 1])) {
          int v1 = find(i * m + idx[j]);
          int v2 = find(i * m + idx[j + 1]);
          G[v1].insert(v2);
          nodes.insert(v1);
          nodes.insert(v2);
        }
      }
    }
  }
  {
    vector<int> idy;
    for (int i = 0; i < n; ++i) idy.push_back(i);
    for (int j = 0; j < m; ++j) {
      sort(idy.begin(), idy.end(), [&](int id1, int id2) {
        if (T(id1, j) != T(id2, j)) return T(id1, j) < T(id2, j);
        return id1 < id2;
      });
      for (int i = 0; i < n - 1; ++i) {
        if (T(idy[i], j) != T(idy[i + 1], j)) {
          int v1 = find(idy[i] * m + j);
          int v2 = find(idy[i + 1] * m + j);
          G[v1].insert(v2);
          nodes.insert(v1);
          nodes.insert(v2);
        }
      }
    }
  }
  solve();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%d ", val[i * m + j]);
    }
    printf("\n");
  }
  return 0;
}
