#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream& operator<<(ostream& os, const pair<first, second>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ",";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream& operator<<(ostream& os, const map<first, second>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
void faltu() { cerr << '\n'; }
template <typename T>
void faltu(T a[], int n) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << '\n';
}
template <typename T, typename... hello>
void faltu(T arg, const hello&... rest) {
  cerr << arg << ' ';
  faltu(rest...);
}
const int mx = 1e6 + 5;
int n, m;
vector<vector<int> > a;
vector<pair<int, int> > vec;
vector<vector<int> > store;
vector<vector<int> > ans;
vector<int> g[mx], grev[mx], adjlist[mx];
int col[mx];
bool vis[mx];
vector<int> toposort;
int dp[mx];
void dfs_topo(int u) {
  vis[u] = 1;
  for (auto v : g[u]) {
    if (!vis[v]) dfs_topo(v);
  }
  toposort.push_back(u);
}
void dfs(int u, int nxt) {
  col[u] = nxt;
  vis[u] = 1;
  for (auto v : grev[u]) {
    if (!vis[v]) dfs(v, nxt);
  }
}
int recur(int pos) {
  if (dp[pos] != -1) return dp[pos];
  int ret = 0;
  for (auto v : adjlist[pos]) {
    ret = max(ret, recur(v));
  }
  dp[pos] = ret + 1;
  return ret + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  a.resize(n + 5, vector<int>(m + 5));
  ans.resize(n + 5, vector<int>(m + 5));
  store.resize(n + 5, vector<int>(m + 5));
  int nxt = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      store[i][j] = nxt++;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    vec.clear();
    for (int j = 1; j <= m; ++j) {
      vec.push_back(make_pair(a[i][j], store[i][j]));
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    for (int j = 1; j < (int)vec.size(); ++j) {
      int u = vec[j - 1].second;
      int v = vec[j].second;
      g[u].push_back(v);
      grev[v].push_back(u);
      if (vec[j - 1].first == vec[j].first) {
        g[v].push_back(u);
        grev[u].push_back(v);
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    vec.clear();
    for (int j = 1; j <= n; ++j) {
      vec.push_back(make_pair(a[j][i], store[j][i]));
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    for (int j = 1; j < (int)vec.size(); ++j) {
      int u = vec[j - 1].second;
      int v = vec[j].second;
      g[u].push_back(v);
      grev[v].push_back(u);
      if (vec[j - 1].first == vec[j].first) {
        g[v].push_back(u);
        grev[u].push_back(v);
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i < nxt; ++i) {
    if (!vis[i]) dfs_topo(i);
  }
  reverse(toposort.begin(), toposort.end());
  memset(vis, 0, sizeof(vis));
  int comp = 0;
  for (auto x : toposort) {
    if (!vis[x]) {
      ++comp;
      dfs(x, comp);
    }
  }
  for (int i = 1; i < nxt; ++i) {
    for (auto v : g[i]) {
      if (col[i] != col[v]) adjlist[col[i]].push_back(col[v]);
    }
  }
  for (int i = 1; i <= comp; ++i) {
    sort(adjlist[i].begin(), adjlist[i].end());
    adjlist[i].erase(unique(adjlist[i].begin(), adjlist[i].end()),
                     adjlist[i].end());
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int temp = recur(col[store[i][j]]);
      ans[i][j] = temp;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cout << ans[i][j] << " ";
    }
    cout << '\n';
  }
}
