#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int INF = 1000000000;

class Mon{
public:
  int y, x, c;
  Mon(int y, int x, int c) : y(y), x(x), c(c) {}
};

int h, w, sy, sx, gy, gx, ans1, ans2;
vector<Mon> node;
int dp[1<<5][1000];
int valm;

bool check(int a, int b){
  int c = (b + 4) % 5;
  return (1<<c) & a;
}

main(){
   while(cin >> w >> h && (h || w)){
     node.clear();
      for(int i=0;i<h;i++){
         for(int j=0;j<w;j++){
            char c;
            cin >> c;
            if(c == 'S'){
               c = '.';
               sy = i;
               sx = j;
            }else if(c == 'G'){
               c = '.';
               gy = i;
               gx = j;
            }else if(c != '.'){
	      node.push_back(Mon(i, j, c-'1'));
            }
         }
      }
      int ans1;
      int ans2 = INF;
      for(int i1=0;i1<5;++i1){
	fill(dp[0], dp[1<<5], INF);
	for(int j=0;j<node.size();++j){
	  if(check(1<<i1, node[j].c)){
	    dp[(1<<i1)|(1<<node[j].c)][j] = min(dp[(1<<i1)|(1<<node[j].c)][j], abs(sy-node[j].y) + abs(sx-node[j].x));
	  }
	}
	for(int i=0;i<(1<<5);i++){
	  for(int j=0;j<node.size();++j){
	    if(dp[i][j] == INF) continue;
	    for(int k=0;k<node.size();++k){
	      if(check(i, node[k].c)){
		dp[i|(1<<node[k].c)][k] = min(dp[i|(1<<node[k].c)][k], dp[i][j] + 
					 abs(node[j].y-node[k].y) + abs(node[j].x-node[k].x));
	      }
	    }
	  }
	} 
	int valm = INF;
	for(int i=0;i<node.size();i++){
	  valm = min(valm, dp[(1<<5)-1][i] + abs(gy-node[i].y) + abs(gx-node[i].x));
	}
	if(ans2 > valm){
	  ans1 = i1;
	  ans2 = valm;
	}
      }
      if(ans2 == INF) cout << "NA" << endl;
      else cout << ans1+1 << ' ' << ans2 << endl;
   }
   return 0;
}