#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cctype>
using namespace std;

const int INF = (int)1e9;

struct Node {
  int y, x, s;
  Node(int y_, int x_, int s_) : y(y_), x(x_), s(s_) { }
};

char F[1000][1001];
int dp[1000][1000][1 << 5];

int main() {
  ios::sync_with_stdio(false);
  while(true) {
    int W, H; cin >> W >> H;
    if(W == 0 && H == 0) break;
    for(int i = 0; i < H; ++i) {
      cin >> F[i];
    }
    int ans = INF;
    int ansS;

    for(int st = 0; st < 5; ++st) {
      queue<Node> Q;
      for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
          for(int k = 0; k < (1 << 5); ++k)
            dp[i][j][k] = INF;
          if(F[i][j] == 'S') {
            dp[i][j][1 << st] = 0;
            Q.emplace(i, j, 1 << st);
          }
        }
      }

      while(!Q.empty()) {
        Node node = Q.front(); Q.pop();
        if(F[node.y][node.x] == 'G' && node.s == (1 << 5) - 1) {
          if(ans > dp[node.y][node.x][node.s]) {
            ans = dp[node.y][node.x][node.s];
            ansS = st;
          }
          break;
        }

        for(int i = 0; i < 4; ++i) {
          int dy[] = { 0, -1, 0, 1 };
          int dx[] = { 1, 0, -1, 0 };
          int nx = node.x + dx[i];
          int ny = node.y + dy[i];
          if(nx < 0 || nx >= W || ny < 0 || ny >= H)
            continue;
          int nextScore = dp[node.y][node.x][node.s] + 1;
          if(dp[ny][nx][node.s] > nextScore) {
            dp[ny][nx][node.s] = nextScore;
            Q.emplace(ny, nx, node.s);
          }
          if(isdigit(F[ny][nx])) {
            int num = F[ny][nx] - '1';
            int S = node.s | (1 << num);
            if(dp[ny][nx][S] > nextScore) {
              dp[ny][nx][S] = nextScore;
              Q.emplace(ny, nx, S);
            }
          }
        }
      }
    }

    if(ans == INF) {
      cout << "NA" << endl;
    }
    else {
      cout << (ansS + 1) << ' ' << ans << endl;
    }
  }
}