change = [[-1, 0], [1, 0], [0, -1], [0, 1]]
inputNum = [j for j in map(int, input().split())]
long = inputNum[0]
length = inputNum[1]
li = [[INF] * (long+1)]
dp = [[0] * (long+1)]
def dfs(i, j):
tmp = 0
for k in change:
if i + k[0] < long+1 and j + k[1] < length+1 and li[i + k[0]][j + k[1]] < li[i][j]:
if dp[i + k[0]][j + k[1]] != -1:
tmp = max(tmp, dp[i + k[0]][j + k[1]])
else:
dfs(i + k[0], j + k[1])
tmp = max(tmp, dp[i + k[0]][j + k[1]])
dp[i][j] = tmp + 1
for i in range(1, long+1):
li.append([INF])
li[i] += [j for j in map(int, input().split())]
dp.append([0])
dp[i] += [-1] * length
for i in range(1, long+1):
for j in range(1, length+1):
if dp[i][j] == -1:
dfs(i, j)
maxone = 0
for i in dp:
maxone = max(max(i), maxone)
print(maxone)```python