#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int d[5][1000];
int x,y;
int sx,sy,gx,gy;
char c;
int nx[5][1000],ny[5][1000],n[5];
int now,next;

int dis(int ay,int ax,int by,int bx){return abs(ay-by)+abs(ax-bx);}

int main(){
  while(scanf("%d %d",&x,&y) && (x||y)){
    for(int i=0;i<5;i++)n[i] = 0;
    
    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
	scanf(" %c ",&c);
	if(c!='.'){
	  if(c=='S'){
	    sx = j;
	    sy = i;
	  }else if(c=='G'){
	    gx = j;
	    gy = i;
	  }else{
	    int a = c-'1';
	    nx[a][n[a]] = j;
	    ny[a][n[a]] = i;
	    n[a]++;
	  }
	}
      }
    }
    
    int type = -1,res = 1<<30;
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++)
	for(int k=0;k<n[j];k++)d[j][k] = 1<<30;

      now = i;
      for(int j=0;j<5;j++){
	next = (now+1)%5;
	if(j==0){
	  for(int k=0;k<n[next];k++){
	    d[next][k] = min(d[next][k],dis(sy,sx,ny[next][k],nx[next][k]));
	  }
	}else if(j==4){
	  int m = 1<<30;
	  for(int k=0;k<n[now];k++){
	    m = min(m,d[now][k] + dis(gy,gx,ny[now][k],nx[now][k]) );
	  }
	  if(m<res){
	    type = i;
	    res = m;
	  }
	}else{
	  for(int k=0;k<n[now];k++){
	    for(int l=0;l<n[next];l++){
	      if(d[now][k]<d[next][l]){
		d[next][l] = min(d[next][l],d[now][k] + dis(ny[now][k],nx[now][k],ny[next][l],nx[next][l]));
	      }
	    }
	  }
	}
	now = next;
      }
    }
    if(type<0)printf("NA\n");
    else printf("%d %d\n",type+1,res);
  }
}