#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;

const int MAX_V = 5050;
const int INF = 1 << 15;

short cost[MAX_V][MAX_V];
short d[MAX_V];
bool used[MAX_V];
int V;

void dijkstra(int s)
{
  fill(d, d + V, INF);
  fill(used, used + V, false);
  d[s] = 0;
  while (true){
    int v = -1;
    for (int u = 0; u < V; u++){
      if (!used[u] && (v == -1 || d[v] < d[v])) v = u;
    }
    if (v == -1) break;
    used[v] = true;
    for (int u = 0; u < V; u++){
      d[u] = min(d[u], (short)(d[v] + cost[v][u]));
    }
  }
}

inline int dist(const P& a, const P& b){
  return abs(a.first - b.first) + abs(a.second - b.second);
}

int main()
{
  int w, h;
  while (scanf("%d %d", &w, &h), w){
    vector<P> ps[5];
    vector<int> is[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));
        }
      }
    }
    V = 2;
    for (int i = 0; i < 5; i++){
      for (auto& p : ps[i]){
        is[i].push_back(V++);
      }
    }
    short mini = INF;
    int mini_id = -1;
    for (int i = 0; i < MAX_V; i++){
      for (int j = 0; j < MAX_V; j++){
        cost[i][j] = INF;
      }
    }
    for (int init = 0; init < 5; init++){
      int nxt = (init + 1) % 5;
      for (int i = 0; i < ps[nxt].size(); i++){
        cost[0][is[nxt][i]] = dist(start, ps[nxt][i]);
      }
      for (int i = 0; i < 3; i++){
        int nnxt = (nxt + 1) % 5;
        for (int j = 0; j < ps[nxt].size(); j++){
          for (int k = 0; k < ps[nnxt].size(); k++){
            cost[is[nxt][j]][is[nnxt][k]] = dist(ps[nxt][j], ps[nnxt][k]);
          }
        }
        nxt = nnxt;
      }
      for (int i = 0; i < ps[nxt].size(); i++){
        cost[is[nxt][i]][1] = dist(goal, ps[nxt][i]);
      }
      dijkstra(0);
      if (mini > d[1]){
        mini = d[1];
        mini_id = init;
      }
    }
    if (mini_id == -1) puts("NA");
    else printf("%d %d\n", mini_id + 1, mini);
  }
  return 0;
}