#include <bits/stdc++.h>

using namespace std;

#define MAX 1000
#define INF 1e9

int H,W,sx,sy,gx,gy;
char field[MAX][MAX];
bool visited[MAX][MAX][1<<5];
const int dx[4] = {-1,0,0,1};
const int dy[4] = {0,-1,1,0};

struct State{
  int x,y,S;
  State(int x,int y,int S) : x(x),y(y),S(S) {}
};

bool check(int S,int p){
  int pc = p-1; 
  if(pc < 0) pc = 4;
  return ((S >> pc) & 1);
}

int solve(int pc){
  queue<State> Q;
  Q.push(State(sx,sy,1<<pc));
  queue<int> d;
  d.push(0);
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      for(int k = 0 ; k < (1<<5) ; k++){
        visited[i][j][k] = false;
      }
    }
  }
  while(!Q.empty()){
    State s = Q.front(); Q.pop();
    int ans = d.front(); d.pop();
    int x = s.x, y = s.y, S = s.S;
    if(visited[y][x][S]) continue;
    visited[y][x][S] = true;
    if(gx == x && gy == y && S == (1<<5)-1){
      return ans;
    }
    for(int i = 0 ; i < 4 ; i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx < 0 || nx >= W || ny < 0 || ny >= H){
        continue;
      }
      if(isdigit(field[ny][nx])){
        int p = (int)(field[ny][nx]-'0')-1;
        if(check(S,p)){
          Q.push(State(nx,ny,S|(1<<p)));
          d.push(ans+1);
        }else{
          Q.push(State(nx,ny,S));
          d.push(ans+1);
        }
      }else{
        Q.push(State(nx,ny,S));
        d.push(ans+1);
      }
    }
  }
  return INF;
}

int main(){
  while(cin >> W >> H, W){
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> field[i][j];
        if(field[i][j] == 'S'){
          sx = j, sy = i;
        }else if(field[i][j] == 'G'){
          gx = j, gy = i;
        }
      }
    }
    int res = INF,num = -1;
    for(int i = 0 ; i < 5 ; i++){
      int t = solve(i);
      if(t < res){
        res = t;
        num = i+1;
      }
    }
    if(res == INF){
      cout << "NA" << endl;
    }else{
      cout << num << " " << res << endl;
    }
  }
  return 0;
}