h,w = map(int,input().split()) a = [list(map(int,input().split())) for i in range(h)] dp = [[0]*w for i in range(h)] seen = [[0]*w for i in range(h)] def dfs(i, j): if seen[i][j]: return dp[i][j] ret = 1 for x, y in [(i+1, j), (i-1, j), (i, j+1), (i, j-1)]: if 0 <= x < h and 0 <= y < w and a[x][y] > a[i][j]: ret = max(ret, dfs(x, y) + 1) dp[i][j] = ret return ret ans = 0 for i in range(h): for j in range(w): ans = max(ans, dfs(i, j)) print(ans)