#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector> dp(h, vector(w, -1)), A(h, vector(w)); auto rec = [&](auto rec, int y, int x) -> int { if(dp[y][x] != -1) return dp[y][x]; dp[y][x] = 1; for(int i = 0; i < 4; i++){ int ny = y + (i == 0) - (i == 1); int nx = x + (i == 2) - (i == 3); if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue; if(A[y][x] < A[ny][nx]) dp[y][x] = max(dp[y][x], rec(rec, ny, nx) + 1); } return dp[y][x]; }; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ cin >> A[y][x]; } } int ans = 0; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ ans = max(ans, rec(rec, y, x)); } } cout << ans << '\n'; }