#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define fi first
#define se second
int h,w,dp[10][1001];
string s;
typedef pair<int,int> P;
vector<P> v[7];
int dist(P a,P b){
	return abs(a.fi-b.fi)+abs(a.se-b.se);
}
main(){
	while(cin>>w>>h,w){
		int ans=1e9,syu=0;
		r(i,7)v[i].clear();
		r(i,h){
			cin>>s;
			r(j,w){
			if(isdigit(s[j]))v[s[j]-'0'].push_back(P(i,j));
			if(s[j]=='S')v[0].push_back(P(i,j));
			if(s[j]=='G')v[6].push_back(P(i,j));
	  	}
		}
		r(o,5){
			int pp=1e9;
			r(i,10)r(j,1001)dp[i][j]=1e9;
			dp[0][0]=0;
			vector<P>px=v[1];
			r(i,4)v[i+1]=v[i+2];
			v[5]=px;
			r(i,4)r(j,v[i].size())r(k,v[i+1].size())
				dp[i+1][k]=min(dp[i+1][k],dp[i][j]+dist(v[i][j],v[i+1][k]));
			r(i,v[4].size())pp=min(pp,dp[4][i]+dist(v[6][0],v[4][i]));
			if(pp<ans){
				ans=pp;
				syu=o+1;
			}
		}
		if(ans==1e9)cout<<"NA"<<endl;
		else cout<<syu<<' '<<ans<<endl;
	}
}