#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 1e6 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n, m, T;
int a[N];
int f[N];
pair<int, int> b[N];
vector<int> w[N];
int ind[N];
int s[N];
int ans[N];
bool check() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < m; ++k) {
        int x = i * m + j;
        int y = i * m + k;
        if (a[x] < a[y] && !(ans[x] < ans[y]) ||
            a[x] > a[y] && !(ans[x] > ans[y]) ||
            a[x] == a[y] && !(ans[x] == ans[y]))
          int pause = 1;
      }
      for (int k = 0; k < n; ++k) {
        int x = i * m + j;
        int y = k * m + j;
        if (a[x] < a[y] && !(ans[x] < ans[y]) ||
            a[x] > a[y] && !(ans[x] > ans[y]) ||
            a[x] == a[y] && !(ans[x] == ans[y]))
          int pause = 1;
      }
    }
  }
  return 1;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  f[y] = x;
}
void ins(int x, int y) {
  x = find(x);
  y = find(y);
  w[x].push_back(y);
  ++ind[y];
}
void spfa() {
  int top = 0;
  for (int i = 0; i < T; ++i) {
    ans[i] = 1;
    if (ind[i] == 0) s[++top] = i;
  }
  while (top) {
    int x = s[top--];
    for (int i = w[x].size() - 1; ~i; --i) {
      int y = w[x][i];
      gmax(ans[y], ans[x] + 1);
      if (--ind[y] == 0) s[++top] = y;
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    T = n * m;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        scanf("%d", &a[i * m + j]);
      }
    }
    for (int i = 0; i < T; ++i) {
      f[i] = i;
      w[i].clear();
      ind[i] = 0;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int o = i * m + j;
        b[j] = make_pair(a[o], o);
      }
      sort(b, b + m);
      for (int j = 1; j < m; ++j) {
        if (b[j].first == b[j - 1].first) {
          int x = b[j].second;
          int y = b[j - 1].second;
          merge(x, y);
        }
      }
    }
    for (int j = 0; j < m; ++j) {
      for (int i = 0; i < n; ++i) {
        int o = i * m + j;
        b[i] = make_pair(a[o], o);
      }
      sort(b, b + n);
      for (int i = 1; i < n; ++i) {
        if (b[i].first == b[i - 1].first) {
          int x = b[i].second;
          int y = b[i - 1].second;
          merge(x, y);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int o = i * m + j;
        b[j] = make_pair(a[o], o);
      }
      sort(b, b + m);
      for (int j = 1; j < m; ++j) {
        if (b[j].first != b[j - 1].first) {
          int x = b[j].second;
          int y = b[j - 1].second;
          ins(y, x);
        }
      }
    }
    for (int j = 0; j < m; ++j) {
      for (int i = 0; i < n; ++i) {
        int o = i * m + j;
        b[i] = make_pair(a[o], o);
      }
      sort(b, b + n);
      for (int i = 1; i < n; ++i) {
        if (b[i].first != b[i - 1].first) {
          int x = b[i].second;
          int y = b[i - 1].second;
          ins(y, x);
        }
      }
    }
    spfa();
    for (int i = 0; i < T; ++i) {
      int x = find(i);
      ans[i] = ans[x];
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        printf("%d ", ans[i * m + j]);
      }
      puts("");
    }
  }
  return 0;
}
