from functools import lru_cache from sys import setrecursionlimit setrecursionlimit(10**5) H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] @lru_cache(maxsize=None) def dfs(i, j): # 4方向全てを見て、大きいものがなければ1を返す res = 1 for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): ni, nj = i + dx, j + dy if 0 <= ni < H and 0 <= nj < W and A[ni][nj] > A[i][j]: res = max(res, dfs(ni, nj) + 1) return res ans = 0 for i in range(H): for j in range(W): ans = max(dfs(i, j), ans) print(ans)