#include <bits/stdc++.h>
using namespace std;
const int maxn=105;
int n,m;
int dir[4][2]={0,1,0,-1,1,0,-1,0};
int vis[maxn][maxn];
struct node{
int x,y,time,prex,prey;
friend bool operator<(node mq,node mp)
{
return mq.time>mp.time;
}
}mp[maxn][maxn];
priority_queue<node>que;
int bfs(){
while(que.size()){
node cur=que.top();
if(cur.x==n-1&&cur.y==m-1) return cur.time;
que.pop();
for(int i=0;i<4;i++){
int dx=cur.x+dir[i][0];
int dy=cur.y+dir[i][1];
if(dx<0||dx>=n||dy<0||dy>=m||mp[dx][dy].time==-1||vis[dx][dy])
continue;
vis[dx][dy]=1;
mp[dx][dy].time+=cur.time+1;
mp[dx][dy].prex=cur.x; mp[dx][dy].prey=cur.y;
que.push(mp[dx][dy]);
}
}
return -1;
}
void printPath(int x,int y){
if(x==0&&y==0) return;
int nx=mp[x][y].prex;
int ny=mp[x][y].prey;
printPath(nx,ny);
int pret=mp[nx][ny].time;
int nt=mp[x][y].time;
cout<<pret+1<<"s:("<<nx<<","<<ny<<")->("<<x<<","<<y<<")"<<endl;
for(int i=pret+2;i<=nt;i++)
cout<<i<<"s:FIGHT AT ("<<x<<","<<y<<")"<<endl;
}
int main(){
while(cin>>n>>m){
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char ch; int t;
cin>>ch;
if(ch=='.') t=0;
else if(ch=='X') t=-1;
else if(ch>='1'&&ch<='9')
t=ch-'0';
mp[i][j].x=i; mp[i][j].y=j;
mp[i][j].time=t;
}
}
while(que.size()) que.pop();
que.push(mp[0][0]);
vis[0][0]=1;
if(bfs()==-1){
cout<<"God please help our poor hero."<<endl;
cout<<"FINISH"<<endl;
continue;
}
else{
cout<<"It takes "<<mp[n-1][m-1].time<<" seconds to reach the target position, let me show you the way."<<endl;
printPath(n-1,m-1);
cout<<"FINISH"<<endl;
}
}
}