1 #include <bits/stdc++.h>
2 using namespace std;
3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
4 const int maxn = 110;
5
6 int m[maxn][maxn];
7 int ms[maxn][maxn];
8 int R,C;
9 int rnt = 1;
10 int dx[] = {1,-1,0,0};
11 int dy[] = {0,0,1,-1};
12 bool valid(int x,int y)
13 {
14 return x>=0 && y>=0 && x<R && y<C;
15 }
16 int msf(int cx,int cy)
17 {
18 if(ms[cx][cy]) return ms[cx][cy];
19 ms[cx][cy] = 1;
20 _for(i,0,4)
21 {
22 int nx = cx+dx[i];
23 int ny = cy+dy[i];
24
25 if(valid(nx,ny) && m[nx][ny] < m[cx][cy])
26 ms[cx][cy] = max(ms[cx][cy],msf(nx,ny)+1);
27 }
28 return ms[cx][cy];
29 }
30 int main()
31 {
32 scanf("%d%d",&R,&C);
33 memset(m,0,sizeof(m));
34 memset(ms,0,sizeof(ms));
35
36 _for(i,0,R)
37 _for(j,0,C)
38 scanf("%d",&m[i][j]);
39
40 _for(i,0,R)
41 _for(j,0,C)
42 rnt = max(rnt,msf(i,j));
43
44 printf("%d\n",rnt);
45 return 0;
46 }