#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<limits.h>
#include<vector>
#include<algorithm>
struct P{int x,y;P(int x,int y):x(x),y(y){}};
int D(P a,P b){return abs(a.x-b.y)+abs(a.y-b.y);}
int main()
{
	int h,w,sx,sy,gx,gy,i,j,k,l,r,a,t;
	char c;
	std::vector<P>v[5];
	std::vector<int>dp[5];
	while(scanf("%d%d",&h,&w),h)
	{
		for(i=0;i<5;++i)v[i].clear();
		for(i=0;i<h;++i)for(j=0;j<w;++j)
		{
			scanf(" %c",&c);
			if(isdigit(c))v[c-'1'].push_back(P(j,i));
			if(c=='S')sx=j,sy=i;
			if(c=='G')gx=j,gy=i;
		}
		a=r=INT_MAX;
		for(i=0;i<5;++i)dp[i].resize(v[i].size());
		for(l=0;l<5;++l)
		{
			for(i=0;i<5;++i)for(j=0;j<dp[i].size();++j)dp[i][j]=INT_MAX;
			t=INT_MAX;
			for(i=0;i<dp[(l+1)%5].size();++i)dp[(l+1)%5][i]=D(P(sx,sy),v[(l+1)%5][i]);
			for(i=1;i<4;++i)
			{
				int pre=(l+i)%5,next=(l+i+1)%5;
				for(j=0;j<dp[next].size();++j)for(k=0;k<dp[pre].size();++k)
				{
					int&r=dp[next][j];
					r=std::min(r,dp[pre][k]+D(v[next][j],v[pre][k]));
				}
			}
			for(i=0;i<dp[(l+4)%5].size();++i)t=std::min(t,dp[(l+4)%5][i]+D(P(gx,gy),v[(l+4)%5][i]));
			if(r>t)r=t,a=l;
		}
		if(r-INT_MAX)printf("%d %d\n",a+1,r);
		else puts("NA");
	}
	return 0;
}