#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[105][105];
int f[105][105];
int n,m;
int ddd(int x, int y) {
if (f[x][y] != 0) return f[x][y];
int xx[] = {1,0,-1,0};
int yy[] = {0,1,0,-1};
int ans = 0;
for (int i = 0; i <= 3; i++) {
int nx = x+xx[i];
int ny = y+yy[i];
if (a[x][y] > a[nx][ny]) {
ans = max(ans,ddd(nx,ny));
}
}
return f[x][y] = ans+1;
}
signed main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(a,127,sizeof(a));
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
for (int j =1; j <= m ;j++){
cin >> a[i][j];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (f[i][j] == 0) {
f[i][j] = ddd(i,j);
ans = max(ans,f[i][j]);
}
}
}
cout << ans;
return 0;
}