#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int INF = (int)1e9;
typedef pair<int, int> P;
int manhattan(P a, P b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
struct State {
  int y, x, monster, firstMonster;
  State(int y_, int x_, int m, int f) : y(y_), x(x_), monster(m), firstMonster(f) {}
  bool operator <(const State &other) const {
    return tie(y, x, monster, firstMonster) < tie(other.y, other.x, other.monster, other.firstMonster);
  }
};
typedef pair<int, State> Node;
int main() {
  ios::sync_with_stdio(false);
  while(true) {
    int X, Y; cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    P sp, gp;
    vector<vector<P>> mp(5);
    REP(i,Y) {
      string F; cin >> F;
      REP(j,X) {
        if(F[j] == 'S') {
          sp = P(i, j);
        }
        if(F[j] == 'G') {
          gp = P(i, j);
        }
        if(isdigit(F[j])) {
          int id = F[j] - '0';
          mp[id - 1].push_back(P(i, j));
        }
      }
    }
    REP(i,5) mp[i].shrink_to_fit();
    P ans(INF, INF);
    priority_queue<Node, vector<Node>, greater<Node>> Q;
    map<State, int> D;
    REP(i,5) {
      Q.emplace(0, State(sp.first, sp.second, 1 << i, i));
    }
    while(!Q.empty()) {
      Node cur = Q.top(); Q.pop();
      // DEBUG(cur.first);
      if(cur.second.y == gp.first && cur.second.x == gp.second && cur.second.monster == (1 << 5) - 1)
        ans = min(ans, make_pair(cur.first, cur.second.firstMonster));
      if(!D.count(cur.second) || D[cur.second] > cur.first) {
        D[cur.second] = cur.first;
        REP(i, 5) {
          if((cur.second.monster >> ((i - 1 + 5) % 5)) & 1) {
            for(P pos : mp[i]) {
              int d = manhattan(pos, make_pair(cur.second.y, cur.second.x));
              Q.emplace(cur.first + d, State(pos.first, pos.second, cur.second.monster | (1 << i), cur.second.firstMonster));
            }
          }
          if(cur.second.monster == (1 << 5) - 1) {
              int d = manhattan(gp, make_pair(cur.second.y, cur.second.x));
              Q.emplace(cur.first + d, State(gp.first, gp.second, cur.second.monster | (1 << i), cur.second.firstMonster));
          }
        }
      }
    }
    if(ans.first == INF) {
      cout << "NA" << endl;
    }
    else {
      cout << ans.second + 1 << ' ' << ans.first << endl;
    }
  }
}