#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.x)+abs(a.y-b.y);}
std::vector<P>v[5];
int X=INT_MAX/10;
int F(int n,P s,P g)
{
	std::vector<int>dp[5];
	int i,j,k,res=X;
	for(i=0;i<5;++i)dp[i].resize(v[i].size()),fill(dp[i].begin(),dp[i].end(),X);
	for(i=0;i<dp[(n+1)%5].size();++i)dp[(n+1)%5][i]=D(s,v[(n+1)%5][i]);
	for(k=1;k<4;++k)
	{
		int next=(n+k+1)%5,pre=(n+k)%5;
		for(i=0;i<dp[next].size();++i)for(j=0;j<dp[pre].size();++j)
		{
			dp[next][i]=std::min(dp[next][i],D(v[next][i],v[pre][j])+dp[pre][j]);
		}
	}
	int last=(n+4)%5;
	for(i=0;i<dp[last].size();++i)res=std::min(res,dp[last][i]+D(v[last][i],g));
	return res;
}
int main()
{
	int h,w,sx,sy,gx,gy,i,j,r,a,t;
	char c;
	while(scanf("%d%d",&w,&h),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;
		}
		r=X;
		for(i=0;i<5;++i)
		{
			t=F(i,P(sx,sy),P(gx,gy));
			if(r>t)r=t,a=i;
		}
		if(r-X)printf("%d %d\n",a+1,r);
		else puts("NA");
	}
	return 0;
}