#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<short, short> P;
 
const int INF = 1 << 29;
 
inline int dist(const P& a, const P& b){
  return abs(a.first - b.first) + abs(a.second - b.second);
}

int dp[6][1024];

int main()
{
  int w, h;
  while (scanf("%d %d", &w, &h), w){
    vector<P> ps[5];

    P start, goal;
    for (int y = 0; y < h; y++){
      char line[1024];
      scanf("%s", line);
      for (int x = 0; x < w; x++){
        if (line[x] == 'S') start = P(x, y);
        else if (line[x] == 'G') goal = P(x, y);
        else if (line[x] != '.') {
          int id = line[x] - '1';
          ps[id].push_back(P(x, y));
        }
      }
    }
    int mini = INF;
    int mini_id = -1;
    for (int init = 0; init < 5; init++){
      for (int i = 0; i < 6; i++) for (int j = 0; j < 1024; j++) dp[i][j] = INF;
      int nxt = (init + 1) % 5;
      for (int i = 0; i < ps[nxt].size(); i++){
        dp[0][i] = dist(start, ps[nxt][i]);
      }
      for (int i = 1; i < 4; i++){
        int nnxt = (nxt + 1) % 5;
        for (int j = 0; j < ps[nxt].size(); j++){
          for (int k = 0; k < ps[nnxt].size(); k++){
            dp[i][k] = min(dp[i][k], dp[i - 1][j] + dist(ps[nxt][j], ps[nnxt][k]));
          }
        }
        nxt = nnxt;
      }
      for (int i = 0; i < ps[nxt].size(); i++){
        int value = dp[3][i] + dist(ps[nxt][i], goal);
        if (mini > value){
          mini = dp[3][i] + dist(ps[nxt][i], goal);
          mini_id = init;
        }
      }
    }
    if (mini == INF) printf("NA\n");
    else printf("%d %d\n", mini_id + 1, mini);
  }
  return 0;
}