#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k,l;
  int x[5][1000],y[5][1000],a[5][1000],b[5],w,h,sx,sy,gx,gy;
  int mn,bm;
  while(cin>>w>>h&&w+h){
    memset(b,0,sizeof(b));
    for(i=0;i<h;i++){
      string s;
      cin>>s;
      for(j=0;j<w;j++){
	if(s[j]=='.'){
	}else if(s[j]=='S'){
	  sx=j;
	  sy=i;
	}else if(s[j]=='G'){
	  gx=j;
	  gy=i;
	}else{
	  x[s[j]-'1'][b[s[j]-'1']]=j;
	  y[s[j]-'1'][b[s[j]-'1']]=i;
	  b[s[j]-'1']++;
	}
      }
    }
    if(!!b[0]+!!b[1]+!!b[2]+!!b[3]+!!b[4]<4)
      cout<<"NA"<<endl;
    else{
      mn=0;
      for(i=0;i<5;i++){
	memset(a,0,sizeof(a));
	for(j=0;j<b[(i+1)%5];j++)
	  a[(i+1)%5][j]=abs(sx-x[(i+1)%5][j])+abs(sy-y[(i+1)%5][j]);
	for(j=1;j<4;j++){
	  for(k=0;k<b[(i+j)%5];k++){
	      for(l=0;l<b[(i+j+1)%5];l++){
		  if(a[(i+j+1)%5][l]==0||a[(i+j+1)%5][l]>abs(x[(i+j+1)%5][l]-x[(i+j)%5][k])+abs(y[(i+j+1)%5][l]-y[(i+j)%5][k])+a[(i+j)%5][k])
		    a[(i+j+1)%5][l]=abs(x[(i+j+1)%5][l]-x[(i+j)%5][k])+abs(y[(i+j+1)%5][l]-y[(i+j)%5][k])+a[(i+j)%5][k];
	      }
	  }
	}
	for(k=0;k<b[(i+j)%5];k++){
	  if(a[(i+j)%5][k]){
	    if(mn==0||mn>abs(gx-x[(i+j)%5][k])+abs(gy-y[(i+j)%5][k])+a[(i+j)%5][k]){
	      mn=abs(gx-x[(i+j)%5][k])+abs(gy-y[(i+j)%5][k])+a[(i+j)%5][k];
	      bm=i+1;	    
	    }
	  }
	}
      }
      cout<<bm<<" "<<mn<<endl;
    }
  }
  return 0;
}