#include<iostream>#include<queue>usingnamespace std;struct Node {int x, y, step;Node(int a =0,int b =0,int c =0){
x = a, y = b, step = c;}friendbooloperator<(Node a, Node b){// 时间消耗大的权值小return a.step > b.step;}};int n, m, sx, sy, gx, gy;char maze[205][205];int vis[205][205];int dx[]={1,0,0,-1};int dy[]={0,1,-1,0};voidbfs(){int ans =0;int flag =0;memset(vis,-1,sizeof(vis));
priority_queue<Node> que;// 优先级高的在队首
que.push(Node(sx, sy,0));
vis[sx][sy]=1;while(!que.empty()){
Node u = que.top();
que.pop();int x = u.x, y = u.y;if(x == gx && y == gy){
ans = u.step;
flag =1;break;}for(int i =0; i <4; i++){int nx = x + dx[i], ny = y + dy[i];if((0<= nx && x < n)&&(0<= ny && ny < m)&&(maze[nx][ny]!='#')&&(vis[nx][ny]==-1)){int step;if(maze[nx][ny]=='x') step = u.step +2;else step = u.step +1;
que.push(Node(nx, ny, step));
vis[nx][ny]=1;}}}if(flag) cout << ans << endl;else cout <<"Poor ANGEL has to stay in the prison all his life."<< endl;}intmain(){while(cin >> n >> m){for(int i =0; i < n; i++)for(int j =0; j < m; j++){
cin >> maze[i][j];if(maze[i][j]=='a') sx = i, sy = j;if(maze[i][j]=='r') gx = i, gy = j;}bfs();}return0;}