#include <iostream>
using namespace std;

struct pati {int x,y,d;};

pati p[5][1000];

int len(int x1,int y1,int x2,int y2) {
	int x,y;
	x=x1-x2; y=y1-y2;
	if (x<0) x=-x;
	if (y<0) y=-y;
	return x+y;
}
int main () {
	int sx,sy,gx,gy,i,j,k,h,p1,p2,f,x,y,d,m,a1,a2,pn[5];
	char c[1000];
	while(cin >> x >> y && x>0) {
		for (i=0;i<5;i++) pn[i]=0; a2=999999999;
		for (i=0;i<y;i++) {
			cin >> c; 
		    for(j=0;j<x;j++) {
				if (c[j]=='S') { sx=j; sy=i; continue;}
				if (c[j]=='G') { gx=j; gy=i; continue;}
				if (c[j]!='.') { k=c[j]-'1'; p[k][pn[k]].x=j; p[k][pn[k]].y=i; pn[k]++;}   
	          }
		  } 
		f=0;
		for (i=0;i<5;i++) if (pn[i]>0) f++;
		if (f<4) { cout << "NA" << endl; continue;}
		for (i=0;i<5;i++) {
			m=(i+1) % 5;
			for (j=0;j<5;j++) for (k=0;k<pn[j];k++) p[j][k].d=99999999;
			if (pn[m]==0) continue;
			for (j=0;j<pn[m];j++) p[m][j].d=len(sx,sy,p[m][j].x,p[m][j].y);			
		    for (j=0;j<3;j++) {
				h=(m+j) % 5; k=(m+j+1) % 5;
				if (pn[k]==0) break;
				for (p1=0;p1<pn[h];p1++) for (p2=0;p2<pn[k];p2++) {
					d=len(p[h][p1].x,p[h][p1].y,p[k][p2].x,p[k][p2].y);
					if (d+p[h][p1].d<p[k][p2].d) p[k][p2].d=d+p[h][p1].d;
				}
			}
			h=(m+3) % 5;
			for (p2=0;p2<pn[h];p2++) {
				k=len(gx,gy,p[h][p2].x,p[h][p2].y);
				if (a2>p[h][p2].d+k) { a1=i+1; a2=p[h][p2].d+k;}
			}
		}
		cout << a1 << ' ' << a2 << endl;
	}   
	return 0;
}