#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

bool memo[1000][1000][1<<5];

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

class State
{
public:
	int m,c,x,y,s;
	State(int x, int y, int c, int m, int s)
	:x(x),y(y),c(c),m(m),s(s)
	{}
	
	bool operator<(const State& a) const
	{
		if(c!=a.c) return c>a.c;
		return s>a.s;
	}
};

int main()
{
	int N,M;
	while(scanf("%d%d", &N,&M), (N||M))
	{
		memset(memo, 0, sizeof(memo));
		int sx,sy;
		char f[1001][1001];
		for(int i=0; i<M; i++)
		{
			for(int j=0; j<N; j++)
			{
				cin >> f[j][i];
				if(f[j][i]=='S')
				{
					sx=j;
					sy=i;
				}
			}
		}
		
		bool g=false;
		priority_queue<State> q;
		for(int i=0; i<5; i++)
		{
			q.push(State(sx,sy,0,(1<<i), i));
		}
		
		while(!q.empty())
		{
			State s=q.top(); q.pop();
			if(s.m==(1<<5)-1 && f[s.x][s.y]=='G')
			{
				g=true;
				cout << s.s+1 << " " << s.c << endl;
				break;
			}
			
			for(int i=0; i<4; i++)
			{
				int tx=s.x+dx[i], ty=s.y+dy[i];
				if(tx<0||ty<0||tx>=N||ty>=M) continue;
				
				int tm=s.m;
				if(isdigit(f[tx][ty]))
				{
					int num=f[tx][ty]-'0'-1;
					if(s.m&(1<<((num+4)%5))) tm |= (1<<num);
				}
				
				if(memo[tx][ty][tm]) continue;
				memo[tx][ty][tm]=1;
				
				q.push(State(tx,ty,s.c+1,tm, s.s));
			}
		}
		
		if(!g) cout << "NA" << endl;
	}
}