#include <stdio.h> #include <stdlib.h> #include <string.h>
#define MAX_N 50
int n, m; int h[MAX_N + 5][MAX_N + 5]; int dp[MAX_N + 5][MAX_N + 5];
int dfs(int x, int y) { if (dp[x][y] != -1) return dp[x][y]; int ans = 1; if (x > 0 && h[x][y] > h[x - 1][y]) ans = max(ans, dfs(x - 1, y) + 1); if (x < n - 1 && h[x][y] > h[x + 1][y]) ans = max(ans, dfs(x + 1, y) + 1); if (y > 0 && h[x][y] > h[x][y - 1]) ans = max(ans, dfs(x, y - 1) + 1); if (y < m - 1 && h[x][y] > h[x][y + 1]) ans = max(ans, dfs(x, y + 1) + 1); return dp[x][y] = ans; }
int main() { memset(dp, -1, sizeof dp); scanf("%d%d", &n, &m); for (int i = 0; i < n; i ++ ) for (int j = 0; j < m; j ++ ) scanf("%d", &h[i][j]); int ans = 0; for (int i = 0; i < n; i ++ ) for (int j = 0; j < m; j ++ ) ans = max(ans, dfs(i, j)); printf("%d\n", ans); return 0; }