Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.

Petya decided to compress tables. He is given a table a consisting of n rows and m columns that is filled with positive integers. He wants to build the table a' consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row i of the initial table ai, j < ai, k, then in the resulting table a'i, j < a'i, k, and if ai, j = ai, k then a'i, j = a'i, k. Similarly, if in some column j of the initial table ai, j < ap, j then in compressed table a'i, j < a'p, j and if ai, j = ap, j then a'i, j = a'p, j. 

Because large values require more space to store them, the maximum value in a' should be as small as possible.

Petya is good in theory, however, he needs your help to implement the algorithm.

Input

The first line of the input contains two integers n and m (<image>, the number of rows and the number of columns of the table respectively.

Each of the following n rows contain m integers ai, j (1 ≤ ai, j ≤ 109) that are the values in the table.

Output

Output the compressed table in form of n lines each containing m integers.

If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.

Examples

Input

2 2
1 2
3 4


Output

1 2
2 3


Input

4 3
20 10 30
50 40 30
50 60 70
90 80 70


Output

2 1 3
5 4 3
5 6 7
9 8 7

Note

In the first sample test, despite the fact a1, 2 ≠ a21, they are not located in the same row or column so they may become equal after the compression.
#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
  edge() {}
  edge(long long a, long long b) { to = a, cost = b; }
};
const long long dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const long long mod = 1000000007;
struct mint {
  long long x = 0;
  mint(long long y = 0) {
    x = y;
    if (x < 0 || x >= mod) x = (x % mod + mod) % mod;
  }
  mint(const mint& ope) { x = ope.x; }
  mint operator-() { return mint(-x); }
  mint operator+(const mint& ope) { return mint(x) += ope; }
  mint operator-(const mint& ope) { return mint(x) -= ope; }
  mint operator*(const mint& ope) { return mint(x) *= ope; }
  mint operator/(const mint& ope) { return mint(x) /= ope; }
  mint& operator+=(const mint& ope) {
    x += ope.x;
    if (x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& ope) {
    x += mod - ope.x;
    if (x >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& ope) {
    x *= ope.x, x %= mod;
    return *this;
  }
  mint& operator/=(const mint& ope) {
    long long n = mod - 2;
    mint mul = ope;
    while (n) {
      if (n & 1) *this *= mul;
      mul *= mul;
      n >>= 1;
    }
    return *this;
  }
  mint inverse() { return mint(1) / *this; }
  bool operator==(const mint& ope) { return x == ope.x; }
  bool operator!=(const mint& ope) { return x != ope.x; }
};
mint modpow(mint a, long long n) {
  if (n == 0) return mint(1);
  if (n % 2)
    return a * modpow(a, n - 1);
  else
    return modpow(a * a, n / 2);
}
istream& operator>>(istream& is, mint& ope) {
  long long t;
  is >> t, ope.x = t;
  return is;
}
ostream& operator<<(ostream& os, mint& ope) { return os << ope.x; }
ostream& operator<<(ostream& os, const mint& ope) { return os << ope.x; }
vector<mint> fact, fact_inv;
void make_fact(int n) {
  fact.resize(n + 1), fact_inv.resize(n + 1);
  fact[0] = mint(1);
  for (long long i = (1); (i) <= (n); (i)++) fact[i] = fact[i - 1] * mint(i);
  fact_inv[n] = fact[n].inverse();
  for (long long i = (n - 1); (i) >= (0); (i)--)
    fact_inv[i] = fact_inv[i + 1] * mint(i + 1);
}
mint comb(long long n, long long k) {
  if (n < 0 || k < 0 || n < k) return mint(0);
  return fact[n] * fact_inv[k] * fact_inv[n - k];
}
mint perm(long long n, long long k) { return comb(n, k) * fact[k]; }
vector<int> prime;
void make_prime(int n) {
  prime.resize(n + 1);
  for (long long i = (2); (i) <= (n); (i)++) {
    if (prime[i]) continue;
    for (int j = i; j <= n; j += i) prime[j] = i;
  }
}
bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }
void mark() { cout << "*" << endl; }
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
long long sgn(long long x) {
  if (x > 0) return 1;
  if (x < 0) return -1;
  return 0;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long digitnum(long long x, long long b = 10) {
  long long ret = 0;
  for (; x; x /= b) ret++;
  return ret;
}
long long digitsum(long long x, long long b = 10) {
  long long ret = 0;
  for (; x; x /= b) ret += x % b;
  return ret;
}
string lltos(long long x) {
  string ret;
  for (; x; x /= 10) ret += x % 10 + '0';
  reverse(ret.begin(), ret.end());
  return ret;
}
long long stoll(string& s) {
  long long ret = 0;
  for (auto c : s) ret *= 10, ret += c - '0';
  return ret;
}
template <typename T>
void uniq(T& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <class S, class T>
pair<S, T>& operator+=(pair<S, T>& s, const pair<S, T>& t) {
  s.first += t.first, s.second += t.second;
  return s;
}
template <class S, class T>
pair<S, T>& operator-=(pair<S, T>& s, const pair<S, T>& t) {
  s.first -= t.first, s.second -= t.second;
  return s;
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T>& s, const pair<S, T>& t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T>& s, const pair<S, T>& t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T>& deq) {
  for (int i = 0; i < deq.size(); i++)
    os << deq[i] << (i + 1 == deq.size() ? "" : " ");
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
  for (typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end();
       itr++) {
    os << "(" << itr->first << ", " << itr->second << ")";
    itr++;
    if (itr != map_var.end()) os << ",";
    itr--;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
  for (typename set<T>::iterator itr = set_var.begin(); itr != set_var.end();
       itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, multiset<T>& set_var) {
  for (typename multiset<T>::iterator itr = set_var.begin();
       itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}
template <typename T>
void outa(T a[], long long s, long long t) {
  for (long long i = s; i <= t; i++) {
    cout << a[i];
    if (i < t) cout << " ";
  }
  cout << endl;
}
void dump_func() { cout << endl; }
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) > 0) cout << " ";
  dump_func(std::move(tail)...);
}
struct SCC {
  int n;
  vector<vector<int> > G, revG, compG;
  vector<int> used, scc, topo;
  int sccid, sccnum;
  void tpdfs(int v) {
    used[v] = 1;
    for (int i = 0; i < G[v].size(); i++) {
      if (!used[G[v][i]]) tpdfs(G[v][i]);
    }
    topo.push_back(v);
  }
  void sccdfs(int v, int id) {
    used[v] = 1;
    scc[v] = id;
    for (int i = 0; i < revG[v].size(); i++) {
      if (!used[revG[v][i]]) sccdfs(revG[v][i], id);
    }
  }
  SCC() {}
  SCC(int n) {
    this->n = n;
    G.resize(n + 1);
    revG.resize(n + 1);
    used.resize(n + 1);
  }
  void init() {
    for (int i = 1; i <= n; i++) {
      G[i].clear(), revG[i].clear();
      used[i] = 0;
    }
    topo.clear();
  }
  void add_edge(int u, int v) { G[u].push_back(v); }
  void tpsort() {
    topo.clear();
    for (int i = 1; i <= n; i++) used[i] = 0;
    for (int i = 1; i <= n; i++)
      if (!used[i]) tpdfs(i);
    reverse(topo.begin(), topo.end());
  }
  bool checkDAG() {
    for (int i = 1; i <= n; i++) used[i] = 0;
    for (int i = 0; i < topo.size(); i++) {
      int v = topo[i];
      used[v] = 1;
      for (int j = 0; j < G[v].size(); j++) {
        if (used[G[v][j]]) return false;
      }
    }
    return true;
  }
  int calcSCC() {
    scc.resize(n + 1);
    for (int i = 1; i <= n; i++) revG[i].clear();
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < G[i].size(); j++) {
        revG[G[i][j]].push_back(i);
      }
    }
    sccid = 1;
    for (int i = 1; i <= n; i++) used[i] = 0;
    for (int i = 0; i < topo.size(); i++)
      if (!used[topo[i]]) sccdfs(topo[i], sccid++);
    return sccnum = sccid - 1;
  }
  void compressSCC(bool simple = false) {
    compG.resize(sccnum + 1);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < G[i].size(); j++) {
        int u = G[i][j];
        if (scc[i] != scc[u]) compG[scc[i]].push_back(scc[u]);
      }
    }
    if (simple) {
      for (int i = 1; i <= sccnum; i++) {
        sort(compG[i].begin(), compG[i].end());
        compG[i].erase(unique(compG[i].begin(), compG[i].end()),
                       compG[i].end());
      }
    }
  }
};
long long h, w;
long long a[1000005];
long long dp[1000005];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> w;
  for (long long y = (0); (y) <= (h - 1); (y)++)
    for (long long x = (0); (x) <= (w - 1); (x)++) cin >> a[y * w + x];
  SCC scc(h * w);
  for (long long y = (0); (y) <= (h - 1); (y)++) {
    vector<pair<long long, long long> > vec;
    for (long long x = (0); (x) <= (w - 1); (x)++)
      vec.push_back(pair<long long, long long>(a[y * w + x], y * w + x + 1));
    sort((vec).begin(), (vec).end());
    for (long long i = (1); (i) <= (w - 1); (i)++) {
      if (vec[i - 1].first <= vec[i].first)
        scc.add_edge(vec[i - 1].second, vec[i].second);
      if (vec[i - 1].first >= vec[i].first)
        scc.add_edge(vec[i].second, vec[i - 1].second);
    }
  }
  for (long long x = (0); (x) <= (w - 1); (x)++) {
    vector<pair<long long, long long> > vec;
    for (long long y = (0); (y) <= (h - 1); (y)++)
      vec.push_back(pair<long long, long long>(a[y * w + x], y * w + x + 1));
    sort((vec).begin(), (vec).end());
    for (long long i = (1); (i) <= (h - 1); (i)++) {
      if (vec[i - 1].first <= vec[i].first)
        scc.add_edge(vec[i - 1].second, vec[i].second);
      if (vec[i - 1].first >= vec[i].first)
        scc.add_edge(vec[i].second, vec[i - 1].second);
    }
  }
  scc.tpsort();
  long long C = scc.calcSCC();
  scc.compressSCC();
  for (long long i = (1); (i) <= (C); (i)++) dp[i] = 1;
  for (long long i = (1); (i) <= (C); (i)++) {
    for (auto u : scc.compG[i]) {
      (dp[u]) = max((dp[u]), (dp[i] + 1));
    }
  }
  for (long long y = (0); (y) <= (h - 1); (y)++) {
    for (long long x = (0); (x) <= (w - 1); (x)++) {
      cout << dp[scc.scc[y * w + x + 1]] << " ";
    }
    cout << endl;
  }
  return 0;
}
