#include<cstdio>
#include<cstring>
#include<cmath>
int g[][];
#define inf 0xffffff
int n,m;
int min;
int sx[]={,,,-};
int sy[]={,,-,};
int que[][];
int front,rear;
void dfs(int x,int y,int c_step)
{
if(x==n&&y==m)
{
if(c_step<min)
{min=c_step;return;}
}
if(abs(x-n)+abs(y-m)+c_step>n*m-)return;
for(int i=;i<;i++)
{
int xx,yy;
xx=x+sx[i];
yy=y+sy[i];
if(xx<=n&&xx>=&&yy<=m&&yy>=&&g[xx][yy]!=-)
{
int zhi=g[xx][yy];
g[xx][yy]=-;
dfs(xx,yy,c_step+zhi+);
g[xx][yy]=zhi;
} } }
int main()
{
char c;
int i,j;
while(scanf("%d %d",&n,&m)!=EOF)
{
getchar();
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
c=getchar();
if(c=='.')
g[i][j]=;
else if(c=='#')
g[i][j]=-;
else
g[i][j]=c-'';
}
getchar();
}
min=inf;
int start=g[][];
dfs(,,start);
printf("\n");
if(min>n*m-)
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",min);
printf("FINISH\n");
}
return ;
}