#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <complex>
#include <queue>
#include <deque>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef pair<int,int> pr;
typedef vector<pr> vpr;
const int INF=1<<30;

int main() {
	// your code goes here
	int x,y;
	pr s,g;
	char tmp;
	while(cin >> x >>y&&x){
	vpr p[5];
	REP(i,y) 
	REP(j,x){
		scanf(" %c",&tmp);
		if(tmp-'1'==-39) continue;
		if(tmp!='.')
			switch(tmp){
				case 'S':
					s=pr(j,i);
					break;
				case 'G':
					g=pr(j,i);
					break;
				default :
					p[tmp-'1'].push_back(pr(j,i));
					break;
			}
	}
	
	int minium[]={INF,INF,INF,INF,INF};
	REP(i,5){
		int DP[5][1000];
		REP(j,5) REP(k,1000) DP[j][k]=INF;
		int v=(i+1)%5;
		REP(j,p[v].size()) DP[v][j]=abs(p[v][j].first-s.first)+abs(s.second+p[v][j].second);

		REP(j,3){
			int c=(i+j+1)%5;
			int ne=(c+1)%5;
			REP(k,p[c].size())
				REP(l,p[ne].size())
					DP[ne][l]=min(DP[ne][l],DP[c][k]+abs(p[c][k].first-p[ne][l].first)+abs(p[c][k].second-p[ne][l].second));
		}
		v=(i+4)%5;
		REP(j,p[v].size()) minium[i]=min(minium[i],DP[v][j]+abs(p[v][j].first-g.first)+abs(p[v][j].second-g.second)); 
	}
	int miniums=0;
	REP(i,5)
		if(minium[miniums]>minium[i])
			miniums=i;
	if(minium[miniums]==INF)
	cout << "NA" << endl;
	else
	cout << miniums+1 << " " <<  minium[miniums] << endl;
	}
	return 0;
}