#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > dp;
int cal(int i , int j , int m , int n , int prev , vector<vector<int>>& matrix) {
if(i<0 || j<0 || matrix[i][j] <= prev || j>=n || i>=m)
return 0;
if(dp[i][j] != -1)
return dp[i][j];
int ans = 0;
int now = matrix[i][j];
ans = max(ans , cal(i-1,j,m,n,now,matrix));
ans = max(ans , cal(i+1,j,m,n,now,matrix));
ans = max(ans , cal(i,j-1,m,n,now,matrix));
ans = max(ans , cal(i,j+1,m,n,now,matrix));
dp[i][j] = 1+ans;
return dp[i][j];
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n , m;
cin >> n >> m;
vector<vector<int> > matrix;
matrix.assign(n , vector<int>(m,0));
for(int i=0 ; i<n ; ++i) {
for(int j=0 ; j<m ; ++j) {
cin >> matrix[i][j];
}
}
dp.assign(matrix.size() , vector<int>(matrix[0].size() , -1));
for(int i=0 ; i<n ; ++i) {
for(int j=0 ; j<m ; ++j) {
cout<<cal(i,j,n,m,-1,matrix)<<" ";
}
cout<<endl;
}
return 0;
}