char map[205][205];
int mt[205][205];//记录最少时间
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int n,m;
bool path(int x,int y)
{
if(x>=0&&x
return false;
}
int BFS(int sx,int sy)
{
priority_queue
cur.x=sx;
cur.y=sy;
cur.time=0;
mt[sx][sy]=0;
q.push(cur);
while(!q.empty())
{
cur=q.top();
q.pop();
if(map[cur.x][cur.y]=='a')
return cur.time;
for(int i=0;i<4;i++)
{
next.x=cur.x+dir[i][0];
next.y=cur.y+dir[i][1];
next.time=cur.time+1;
if(map[next.x][next.y]=='x')
next.time++;
if(path(next.x,next.y)&&next.time
mt[next.x][next.y]=next.time;
q.push(next);
}
}
}
return -1;
}
int main()
{
int i,j,sx,sy;
while(~scanf("%d%d",&n,&m))
{
for(i=0;i
for(i=0;i
if(map[i][j]=='r')
{
sx=i;
sy=j;
}
mt[i][j]=100000000;
}
int res=BFS(sx,sy);
if(res==-1)
printf("Poor ANGEL has to stay in the prison all his life.\n");
else
printf("%d\n",res);
}
return 0;
}