#include<bits/stdc++.h> usingnamespace std; constint N = 1e3 + 9;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int n, m; int a[N][N], s[N][N], ans;
intdfs(int x, int y) { if (s[x][y]) return s[x][y]; s[x][y] = 1; for (int i = 0; i <= 3; i++) { int xx = dx[i] + x; int yy = dy[i] + y; if (xx > 0 && yy > 0 && xx <= n && yy <= m && a[x][y] > a[xx][yy]) { dfs(xx, yy); s[x][y] = max(s[x][y], s[xx][yy] + 1); } } return s[x][y]; }
intmain() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (registerint i = 1; i <= n; i++) for (registerint j = 1; j <= m; j++) ans = max(ans, dfs(i, j)); cout << ans << endl; return0; }