#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;
char fie[1001][1001];
int gx,gy;

int vnums[5];

int dp[6][1001][1001];

inline int ab(int a){return a<0?-a:a;}

int solve(int no,int id,int zen,int syo){
  int ind=(no+syo+1)%5;
  int k=(no+syo)%5;
  int res=INF;
  if(dp[no][id][zen]!=-1) return dp[no][id][zen];
  if(id>=vnums[k])
    return dp[no][id][zen]=INF;
  if(no==4)
    return ab(gx-node[k][zen].first)+ab(gy-node[k][zen].second);
  res=min(
	  solve(no+1,1,id,syo)
	  +ab(node[k][zen].first-node[ind][id].first)
	  +ab(node[k][zen].second-node[ind][id].second),
	  solve(no,id+1,zen,syo)
	  );
  return dp[no][id][zen]=res;
}

main(){
int sx,sy;
  while(1){
    scanf("%d %d",&X,&Y); getchar();
    if(!X && !Y) break;

    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++){
	//cin >> fie[j][i];
	//scanf(" %c",fie[j]+i);
	while((fie[j][i] = getchar())=='\n');
	if(fie[j][i]=='S'){
	  sx=j;
	  sy=i;
	  for(int k=0;k<5;k++)
	    node[k].push_back(P(sx,sy));
	}
      }
    }

    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++){

	if(fie[j][i]>='1' && fie[j][i]<='5') {
	  node[fie[j][i]-'1'].push_back(P(j,i));
	}

	if(fie[j][i]=='G'){
	  gx=j;
	  gy=i;
	}

      }
    }

    for(int i=0;i<5;i++)
      vnums[i]=node[i].size();
    int aaaa;
    int res=INF;
    for(int i=0;i<5;i++){
      memset(dp,-1,sizeof(dp));
      int ret = solve(0,1,0,i);
      if( res > ret ) {
	res = ret;
	aaaa = i+1;
      }
    }

    if(res==INF) {
      puts("NA");
    } else {
      printf("%d %d\n",aaaa,res);
    }
    for(int i = 0; i < 5; i++) node[i].clear();
  }
}