#include <bits/stdc++.h>

using namespace std;

#define INF 1e9
typedef pair<int,int> pii;

struct Point{
  int x,y;
};

int cnt[5];
int dp[5][1002];
Point cr[5][1002];

int getMD(const Point &p1,const Point &p2){
  return abs(p1.x-p2.x)+abs(p1.y-p2.y);
}

int main(){
  int H,W;
  while(cin >> W >> H, W){
    char in;    
    int sx,sy,gx,gy;
    memset(cnt,0,sizeof(cnt));
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> in;
        if(in == 'S'){
          sx = j; sy = i;
        }else if(in == 'G'){
          gx = j; gy = i;
        }else if(isdigit(in)){
          int n = in-'1';
          cr[n][cnt[n]++] = (Point){j,i};
        }
      }
    }
    for(int i = 0 ; i < 5 ; i++){
      cr[i][cnt[i]++] = (Point){sx,sy};
      cr[i][cnt[i]++] = (Point){gx,gy};
    }
    int res = INF, num = -1;
    for(int i = 0 ; i < 5 ; i++){
      for(int j = 0 ; j < 5 ; j++){
        for(int k = 0 ; k < cnt[j] ; k++){
          dp[j][k] = INF;
        }
      }
      dp[i][cnt[i]-2] = 0;
      int now = i,j = (i != 4 ? i+1 : 0),ej = (i > 0 ? i-1 : 4);
      while(j != i){
        for(int k = 0 ; k < cnt[now] ; k++){
          if(dp[now][k] == INF) continue;
          int m = j != ej ? 2 : 0;
          for(int l = 0 ; l < cnt[j]-m ; l++){
            dp[j][l] = min(dp[j][l],dp[now][k]+getMD(cr[now][k],cr[j][l]));
          }
        }
        now = now+1 == 5 ? 0 : now+1;
        j = j+1 == 5 ? 0 : j+1;
      }
      if(dp[now][cnt[now]-1] < res){
        res = dp[now][cnt[now]-1];
        num = i+1;
      }
    }
    if(res == INF){
      cout << "NA" << endl;
    }else{
      cout << num << " " << res << endl;
    }
  }
  return 0;
}