#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
#define INF (1<<20)
typedef pair<int,int> P;
vector<P> node[5];
int X,Y;
int sx,sy;
int gx,gy;
char fie[1001][1001];

int vnums[5];

int dp[6][1002][1002];
int solve(int no,int id,int zen,int syo){
  int ind=(no+syo)%5;
  int res=INF;
  if(dp[no][id][zen]!=-1) return dp[no][id][zen];
  if(no==4)
    return abs(gx-node[ind][zen].first)+abs(gy-node[ind][zen].second);
  if(id>=vnums[(ind+1)%5])
    return dp[no][id][zen]=INF;
  res=min(solve(no+1,1,id,syo)+abs(node[ind][zen].first-node[(ind+1)%5][id].first)+abs(node[ind][zen].second-node[(ind+1)%5][id].second), solve(no,id+1,zen,syo));
  /*  printf("(%d,%d)-(%d,%d)=%d\n",node[ind][zen].first,node[ind][zen].second,
	 node[(ind+1)%5][id].first,node[(ind+1)%5][id].second,
	 abs(node[ind][zen].first-node[(ind+1)%5][id].first)+abs(node[ind][zen].second-node[(ind+1)%5][id].second));*/
  //  printf(" %d - %d->%d ret=%d\n",no,ind,(ind+1)%5,res);
  return dp[no][id][zen]=res;
}

main(){
  while(1){
    scanf("%d %d",&X,&Y);
    if(!X && !Y) break;
    memset(vnums,0,sizeof(vnums));

    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++){
	cin >> fie[j][i];
	if(fie[j][i]=='S'){
	  sx=j;
	  sy=i;
	  for(int k=0;k<5;k++)
	    node[k].push_back(P(sx,sy));
	}
	else if(fie[j][i]>='1' && fie[j][i]<='5')
	  node[fie[j][i]-'1'].push_back(P(j,i));
	else if(fie[j][i]=='G'){
	  gx=j;
	  gy=i;
	}
      }
    }

    for(int i=0;i<5;i++){
      vnums[i]=node[i].size();
      /* for(int j=0;j<vnums[i];j++){
	printf("%d属性 %d番目 %d,%d\n",i,j,node[i][j].first,node[i][j].second); 
	}*/
    }
    
    int res=INF;
    int tmp=res;
    int res2=-1;
    for(int i=0;i<5;i++){
      memset(dp,-1,sizeof(dp));
      tmp=solve(0,1,0,i);
      //    printf("%dres=%d\n",i,tmp);
      if(res>tmp){
	res2=i;
	res=tmp;
      }
    }
    if(res2==-1)
      printf("NA\n");
    else
      printf("%d %d\n",res2+1,res);

    for(int i=0;i<5;i++)
      node[i].clear();
  }




}