#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int INF = (1<<21);

int px[5][1000];
int py[5][1000];
int table[5][1000];
int p[5];
char m[1001];
int dist(int x,int y){
  if ( x < 0)x*=-1;
  if ( y <0)y*=-1;
  return x+y;
}
#define NEXT(i) ( (i+1)%5)
int solve(int ini,int sx,int sy,int gx,int gy){
  rep(i,5)rep(j,1000)table[i][j]=INF;
  ini=(ini+1)%5;
  rep(i,p[ini]){
    table[ini][i]=dist(sx-px[ini][i],sy-py[ini][i]);
  }
  

  rep(i,3){
    rep(j,p[(ini)]){
      rep(k,p[NEXT(ini)]){
	table[NEXT(ini)][k]=min(table[NEXT(ini)][k]
				,table[ini][j]+dist(px[ini][j]-px[NEXT(ini)][k],
						    py[ini][j]-py[NEXT(ini)][k]));
      }
    }
    ini=(ini+1)%5;
  }

  int ans = INF;
  rep(i,p[ini]){
    ans = min(ans,table[ini][i]+dist(gx-px[ini][i],gy-py[ini][i]));
  }
  return ans;
}

int main(){
  int c,r;
  while(cin>>c>>r && c){
    int sx,sy,gx,gy;
    rep(i,5)p[i]=0;
    rep(i,r){
      cin>>m;
      rep(j,c){
	if ( m[j] == 'S')sx=j,sy=i;
	else if (m[j] == 'G')gx=j,gy=i;
	else if ( m[j] != '.'){
	  int now =m[j]-'0'-1;
	  py[now][p[now]]=i;
	  px[now][p[now]]=j;
	  p[now]++;
	}
      }
    }


    int ans=INF,ansindex =-1;
    rep(i,5){
      int tmp = solve(i,sx,sy,gx,gy);
      if ( tmp < ans)ans=tmp,ansindex=i;
    }

    if ( ansindex == -1)cout << "NA"<<endl;
    else cout << ansindex+1 <<" " << ans << endl;
  }
  return false;
}