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

using namespace std;

const int INF = 1000000000;

class cre{
public:
   int y, x, col;
};

int h, w, gy, gx, sy, sx, ans1, ans2;
char mapData[1000][1000];
int visited[1<<5][1000];
vector<cre> node;
int valm;

void dfs(int p, int cost, int s){
   visited[s][p] = cost;
   if(s == (1<<5)-1){
      valm = min(valm, cost + abs(node[p].y-gy)+abs(node[p].x-gx));
   }
   for(int i=1;i<node.size();i++){
      int coler = (node[i].col + 4) % 5;
      if(!(s & (1<<coler))) continue;
      int tmp = cost + abs(node[p].y-node[i].y)+abs(node[p].x-node[i].x);
      if(visited[s|(1<<node[i].col)][i] <= tmp) continue;
      dfs(i, tmp, s|(1<<node[i].col));
   }
}

main(){
   while(cin >> w >> h && (h || w)){
      node.clear();
      for(int i=0;i<h;i++){
         for(int j=0;j<w;j++){
            cin >> mapData[i][j];
            cre tmp;
            if(mapData[i][j] == 'S'){
               mapData[i][j] = '.';
               tmp.y = i;
               tmp.x = j;
               tmp.col = -1;
               node.push_back(tmp);
            }else if(mapData[i][j] == 'G'){
               mapData[i][j] = '.';
               gy = i;
               gx = j;
            }else if(mapData[i][j] != '.'){
               tmp.y = i;
               tmp.x = j;
               tmp.col = mapData[i][j] - '1';
               node.push_back(tmp);
            }
         }
      }
      ans1 = -1;
      ans2 = INF;
      for(int i=0;i<5;i++){
         fill(visited[0], visited[1<<5], INF);
         valm = INF;
         dfs(0, 0, (1<<i));
         if(valm != INF){
            if(ans2 > valm){
               ans1 = i;
               ans2 = valm;
            }
         }
      }
      if(ans1 == -1) cout << "NA" << endl;
      else cout << ans1+1 << ' ' << ans2 << endl;
   }
   return 0;
}