#include<iostream>
#include<vector>
#include<map>
#include<cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int w,h;while(cin>>w>>h,w){
		int sx,sy,gx,gy,ai,ans=1<<20,t;
		vector<pair<int,int> > pos[5];
		vector<int> cost[5];
		char buf[1001];
		rep(i,h){
			cin>>buf;
			rep(j,w){
				if(buf[j]=='S')sy=i,sx=j;
				if(buf[j]=='G')gy=i,gx=j;
				if('0'<buf[j]&&buf[j]<'6')pos[buf[j]-'1'].push_back(make_pair(i,j));
			}
		}
		rep(i,5)cost[i].resize(pos[i].size());
		rep(i,5){
			int ni=(i+3)%5;
			rep(j,5)fill(cost[j].begin(),cost[j].end(),1<<20);
			rep(j,cost[i].size())cost[i][j]=abs(sy-pos[i][j].first)+abs(sx-pos[i][j].second);
			for(int j_=i;j_<i+3;j_++){
				int j=j_%5,nj=(j+1)%5;
				rep(k,cost[nj].size())rep(l,cost[j].size())
				cost[nj][k]=min(cost[j][l]+
					abs(pos[nj][k].first-pos[j][l].first)+
					abs(pos[nj][k].second-pos[j][l].second),
					cost[nj][k]);
			}
			rep(j,cost[ni].size()){
				int nc=cost[ni][j]+abs(gy-pos[ni][j].first)+abs(gx-pos[ni][j].second);
				if(ans>nc)ans=nc,ai=i;
			}
		}
		if(ans==1<<20)cout<<"NA"<<endl;
		else cout<<ai<<" "<<ans<<endl;
	}
	return 0;
}