#include void solve() { int h, w; std::cin >> h >> w; auto encode = [&](int i, int j) { return i * w + j; }; std::vector a(h, std::vector(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { std::cin >> a[i][j]; } } std::vector graph(h * w, std::vector()); const int DI[] = {1, 0, -1, 0}; const int DJ[] = {0, 1, 0, -1}; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int k = encode(i, j); for (int d = 0; d < 4; d++) { int ni = i + DI[d]; int nj = j + DJ[d]; if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue; if (a[i][j] >= a[ni][nj]) continue; int nk = encode(ni, nj); graph[k].push_back(nk); } } } std::vector dp(h * w, -1); auto dfs = [&](auto self, int u) -> int { if (dp[u] != -1) return dp[u]; dp[u] = 1; for (int v: graph[u]) { dp[u] = std::max(dp[u], self(self, v) + 1); } return dp[u]; }; int ans = 0; for (int i = 0; i < h * w; i++) { ans = std::max(ans, dfs(dfs, i)); } std::cout << ans << '\n'; } int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(16); int t = 1; while (t--) solve(); }