#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
struct na{
int x,y;
};
const int fx[8]={1,2,1,2,-1,-2,-1,-2},fy[8]={2,1,-2,-1,2,1,-2,-1};
int n,m,sx,sy,tx,ty;
int map[31][31];
char cc;
int f[31][31],l[31][31];
long long p[31][31];
bool bo[31][31];
int read(){
int a=0;
cc=getchar();
while(cc<‘0‘||cc>‘9‘) cc=getchar();
while(cc>=‘0‘&&cc<=‘9‘) a=a*10+cc-48,cc=getchar();
return a;
}
queue <na> q;
const int INF=10000;
int main(){
n=read();m=read();
for (int i=0;i<n;i++)
for (int j=0;j<m;j++){
map[i][j]=read();
if (map[i][j]==3) sx=i,sy=j,map[i][j]=1;
if (map[i][j]==4) tx=i,ty=j,map[i][j]=1;
f[i][j]=l[i][j]=INF;
}
na cmp;
cmp.x=sx;cmp.y=sy;
f[sx][sy]=l[sx][sy]=0;p[sx][sy]=1;
bo[sx][sy]=1;
q.push(cmp);
while(!q.empty()){
na k=q.front();q.pop();
bo[k.x][k.y]=0;
if (k.x==tx&&k.y==ty) continue;
for (int i=0;i<8;i++){
na now=k;
now.x+=fx[i];now.y+=fy[i];
if (now.x<0||now.y<0||now.x>=n||now.y>=m) continue;
if (map[now.x][now.y]==2) continue;
if (f[now.x][now.y]>f[k.x][k.y]+(map[now.x][now.y]==0)){
f[now.x][now.y]=f[k.x][k.y]+(map[now.x][now.y]==0);
l[now.x][now.y]=l[k.x][k.y]+1;
p[now.x][now.y]=p[k.x][k.y];
if (bo[now.x][now.y]==0){
q.push(now);
bo[now.x][now.y]=1;
}
}else if (f[now.x][now.y]==f[k.x][k.y]+(map[now.x][now.y]==0)){
if (l[now.x][now.y]>l[k.x][k.y]+1){
l[now.x][now.y]=l[k.x][k.y]+1;
p[now.x][now.y]=p[k.x][k.y];
if (bo[now.x][now.y]==0){
q.push(now);
bo[now.x][now.y]=1;
}
}else if (l[now.x][now.y]==l[k.x][k.y]+1){
p[now.x][now.y]+=p[k.x][k.y];
if (bo[now.x][now.y]==0){
q.push(now);
bo[now.x][now.y]=1;
}
}
}
}
}
if (f[tx][ty]==INF) printf("-1");else printf("%d\n%d\n%lld",f[tx][ty],l[tx][ty],p[tx][ty]);
}