#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);
}
int dp[5][1000];
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));
        }
      }
    }
    P ans(INF, INF);
    REP(i,5) {
      REP(j,5) REP(k,1000) dp[j][k] = INF;
      int begin = (i + 1) % 5;
      REP(k, mp[begin].size()) {
        dp[begin][k] = manhattan(sp, mp[begin][k]);
      }
      for(int j = 2; j <= 4; ++j) {
        int prev = (i + j - 1) % 5;
        int next = (i + j) % 5;
        REP(k, mp[prev].size()) {
          REP(l, mp[next].size()) {
            int d = dp[prev][k] + manhattan(mp[prev][k], mp[next][l]);
            dp[next][l] = min(dp[next][l], d);
          }
        }
      }
      int end = (i + 4) % 5;
      REP(k, mp[end].size()) {
        ans = min(ans, make_pair(dp[end][k] + manhattan(mp[end][k], gp), i));
      }
    }
    if(ans.first == INF) {
      cout << "NA" << endl;
    }
    else {
      cout << ans.second + 1 << ' ' << ans.first << endl;
    }
  }
}