#include<iostream>
#include<cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int w,h,m[1000][1000],sx,sy,gx,gy,cost[32][1000][1000],ans,e;
void dfs(int y,int x,int s){
	if(cost[s][y][x]+abs(gy-y)+abs(gx-x)>cost[31][gy][gx])return;
	rep(d,4){
		int ny=y+dy[d],nx=x+dx[d],ns;
		if(!ck(ny,h)||!ck(nx,w))continue;
		ns=m[ny][nx]!=0&&(s&1<<(m[ny][nx]+3)%5)?s|1<<(m[ny][nx]-1):s;
		if(cost[ns][ny][nx]>cost[s][y][x]+1){
			if(ny==gy&&nx==gx&&ns==31)ans=e;
			cost[ns][ny][nx]=cost[s][y][x]+1,dfs(ny,nx,ns);
		}
	}
}
int main(){
	while(cin>>w>>h,w){
		int f[5]={0},count=0;
		rep(i,h)rep(j,w){
			char c;cin>>c;
			if(c=='S')sy=i,sx=j;
			if(c=='G')gy=i,gx=j;
			if('0'<c&&c<'6')f[c-'1']=1,m[i][j]=c-'0';
			else m[i][j]=0;
			rep(k,32)cost[k][i][j]=1<<20;
		}
		rep(i,5)count+=f[i],cost[1<<i][sy][sx]=0;
		if(count<4){
			cout<<"NA"<<endl;continue;
		}
		rep(i,5)e=i,dfs(sy,sx,1<<i);
		cout<<ans+1<<" "<<cost[31][gy][gx]<<endl;
	}
	return 0;
}