#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
int x,y;
int gx,gy;
int sx,sy;
vector <int> typex[6];
vector <int> typey[6];

int solve(int nx,int ny,int ty){
  int ret=0;
  for(int i=ty%5+1;i!=ty;i=i%5+1){
    int n=typex[i].size();
    int lar=( 1<<22 );
    int temp=lar;
    int mx,my;
    for(int j=0;j<n;j++){
      temp=min(lar,abs(sx-typex[i][j])+abs(sy-typey[i][j]));
      //      printf("%d %d %d ... %d\n",typex[i][j],typey[i][j],i,abs(sx-typex[i][j])+abs(sy-typey[i][j]));
      if(temp!=lar){
	lar=temp;
	mx=typex[i][j]; my=typey[i][j];
      }
    }
    nx=mx; ny=my;
    ret+=lar;
    //    printf("%dのとき:%d\n",i,ret);
  }
  return ret;
}

main(){
  while(1){
    int f[7]={0};
    scanf("%d %d",&x,&y);
    if(!x && !y) break;
    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
	char c;
	cin >> c;
	if(c=='.') continue;
	if(c=='S'){ sx=j; sy=i;}
	else if(c=='G'){ gx=j; gy=i;}
	else {
	  f[c-'0']=1;
	  typex[c-'0'].push_back(j);
	  typey[c-'0'].push_back(i);
	}
      }
    }
    for(int i=1;i<=5;i++){
      if(f[i]==0){ printf("NA\n"); f[0]=-1; break; }
    }
    if(f[0]==-1) continue;
    int res=( 1<<20 );
    int temp=res;
    int rei;
    for(int i=1;i<=5;i++){
      int  ret=solve(sx,sy,i);
      //   printf("%d\n",ret);
      temp=min(res,ret);
      if(temp!=res){ res=temp; rei=i;}
    }
    printf("%d %d\n",rei,res);
  }

}