//带路径的BFS
//记录着父亲,以及入队的要求就好了
#include"stdio.h"
#include"iostream"
#include"queue"
using namespace std;
#define MAX 9999999
char str[200][200];
int dis[10001];
int n,m;
int parent[10001];
int fx(int v)
{
if(v%m!=0)
return v/m;
else
return v/m-1;
}
int fy(int v)
{
if(v%m!=0)
return v%m-1;
else
return m-1;
}
int fv(int x,int y)
{
return x*m+y+1;
}
void bfs()
{
int v;
int i,j;
int lp;
queue<int> q;
int vx,vy;
for(i=0;i<10001;i++)
dis[i]=9999999;
dis[1]=0;
q.push(1);
while(q.empty()==0)
{
v=q.front();
q.pop();
vx=fx(v);
vy=fy(v);
if(vx-1>=0 && str[vx-1][vy]!='X')
{
if(str[vx-1][vy]>='1' && str[vx-1][vy]<='9' )
{
if(dis[fv(vx-1,vy)]>dis[v]+(str[vx-1][vy]-'0')+1)
{
q.push(fv(vx-1,vy));
dis[fv(vx-1,vy)]=dis[v]+(str[vx-1][vy]-'0')+1;
parent[fv(vx-1,vy)]=v;
}
}
else
{
if(dis[fv(vx-1,vy)]>dis[v]+1)
{
q.push(fv(vx-1,vy));
dis[fv(vx-1,vy)]=dis[v]+1;
parent[fv(vx-1,vy)]=v;
}
}
}
if(vx+1<n && str[vx+1][vy]!='X')
{
if(str[vx+1][vy]>='1' && str[vx+1][vy]<='9')
{
if(dis[fv(vx+1,vy)]>dis[v]+(str[vx+1][vy]-'0')+1)
{
dis[fv(vx+1,vy)]=dis[v]+(str[vx+1][vy]-'0')+1;
parent[fv(vx+1,vy)]=v;
q.push(fv(vx+1,vy));
}
}
else
{
if(dis[fv(vx+1,vy)]>dis[v]+1)
{
dis[fv(vx+1,vy)]=dis[v]+1;
parent[fv(vx+1,vy)]=v;
q.push(fv(vx+1,vy));
}
}
}
if(vy-1>=0 && str[vx][vy-1]!='X')
{
lp=fv(vx,vy-1);
if(str[vx][vy-1]>='1' && str[vx][vy-1]<='9')
{
if(dis[lp]>dis[v]+(str[vx][vy-1]-'0')+1)
{
dis[lp]=dis[v]+(str[vx][vy-1]-'0')+1;
parent[lp]=v;
q.push(lp);
}
}
else
{
if(dis[lp]>dis[v]+1)
{
dis[lp]=dis[v]+1;
parent[lp]=v;
q.push(lp);
}
}
}
if(vy+1<m && str[vx][vy+1]!='X')
{
lp=fv(vx,vy+1);
if(str[vx][vy+1]>='1' && str[vx][vy+1]<='9')
{
if(dis[lp]>dis[v]+(str[vx][vy+1]-'0')+1)
{
dis[lp]=dis[v]+(str[vx][vy+1]-'0')+1;
parent[lp]=v;
q.push(lp);
}
}
else
{
if(dis[lp]>dis[v]+1)
{
dis[lp]=dis[v]+1;
parent[lp]=v;
q.push(lp);
}
}
}
}
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(parent,-1,sizeof(parent));
for(i=0;i<n;i++)
cin>>str[i];
bfs();
if(dis[fv(n-1,m-1)]>=MAX)
{
printf("God please help our poor hero.\n");
}
else{
printf("It takes %d seconds to reach the target position, let me show you the way.\n",dis[fv(n-1,m-1)]);
int x;
x=fv(n-1,m-1);
int luo[1002];
int num=0;
while(x!=1)
{
luo[num]=x;
num++;
x=parent[x];
}
luo[num]=1;
int t=1;
int l,p;
l=fx(luo[num]);
p=fy(luo[num]);
int z1,z2;
for(i=num-1;i>=0;i--)
{
z1=fx(luo[i]);
z2=fy(luo[i]);
printf("%ds:",t);
t++;
printf("(%d,%d)->(%d,%d)\n",l,p,z1,z2);
if(str[z1][z2]>='0' && str[z1][z2]<='9')
{
for(j=1;j<=(str[z1][z2]-'0');j++)
{
printf("%ds:",t);
t++;
printf("FIGHT AT (%d,%d)\n",z1,z2);
}
}
l=z1;
p=z2;
}
}
printf("FINISH\n");
}
return 0;
}