#include<bits/stdc++.h>
using namespace std;
int n,m;
bool flag=false,vis[505][505],mark[505][505];
struct Edge
{
int high,num;
}h[505][505];
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
struct Point
{
int x,y,high;
friend bool operator < (const Point &a,const Point &b)
{
return a.high>b.high;
}
}a[1001];
set<int> s;
queue<Point> q;
inline bool check(int x,int y,int high)
{
if(x>=1 and x<=n and y>=1 and y<=m and vis[x][y]==false and h[x][y].high<high)
{
return true;
}
return false;
}
inline bool judge()
{
for(int i=1;i<=m;i++)
{
if(vis[n][i]==false)
{
return false;
}
}
return true;
}
inline void BFS(int x,int y,int high)
{
while(!q.empty())
{
q.pop();
}
q.push(Point{x,y,high});vis[x][y]=true;
while(!q.empty())
{
Point temp=q.front();q.pop();
for(int i=0;i<4;i++)
{
int xx=temp.x+dx[i],yy=temp.y+dy[i];
if(check(xx,yy,temp.high)==true)
{
q.push(Point{xx,yy,h[xx][yy].high});
h[xx][yy].num=y;vis[xx][yy]=true;
if(judge()==true)
{
flag=true;
break;
}
}
}
}
return ;
}
signed main(void)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&h[i][j].high);
}
}
for(int i=1;i<=m;i++)
{
a[i].high=h[1][i].high;a[i].y=i;a[i].x=1;
}
sort(a+1,a+1+m);
for(int i=1;i<=m;i++)
{
if(vis[1][a[i].y]==false)
{
BFS(1,a[i].y,h[1][a[i].y].high);
}
if(flag==true)
{
break;
}
}
if(flag==false)
{
printf("0\n");int cnt=0;
for(int i=1;i<=m;i++)
{
if(vis[n][i]==false)
{
cnt++;
}
}
printf("%d\n",cnt);
}
else
{
for(int i=1;i<=m;i++)
{
if(h[n][i].num!=0)
{
s.insert(h[n][i].num);
}
}
printf("1\n%d",s.size());
}
return 0;
}