#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef pair<int,int> pii;

int hoge(int i, int m) {
  if(i==0) return 0;
  return (i+m-1)%6+1;
}

int main() {
  int X,Y;
  while(cin >> X >> Y, X+Y) {
    char ba[X][Y];
    vector<pii> v[7];
    REP(y,Y)REP(x,X) {
      cin >> ba[x][y];
      if (ba[x][y] == 'S') {
        v[0].push_back(pii(x,y));
      } else if (ba[x][y] == 'G') {
        v[6].push_back(pii(x,y));
      } else if (ba[x][y] != '.') {
        v[ba[x][y] - '0'].push_back(pii(x,y));
      }
    }
    if (!v[1].size() || !v[2].size() || !v[3].size() || !v[4].size() || !v[5].size()) {
      cout << "NA" << endl;
      continue;
    }
    vector<int> dp[7];
    REP(i,7) dp[i] = vector<int>(v[i].size(), INF);
    dp[0][0] = 0;
    int ans = 0;
    int mi = INF;
    REP(m,5) {
      REP(i, 6) {
        int ii = hoge(i, m);
        int jj = hoge(i+1,m);
//        printf("%d,%d\n",ii,jj);
        REP(j, v[ii].size()) {
          REP(k, v[jj].size()) {
            dp[jj][k] = min(dp[jj][k],
                            dp[ii][j]
                            + abs(v[ii][j].first - v[jj][k].first)
                            + abs(v[ii][j].second - v[jj][k].second));
            //          printf("%d, %d  (%d)\n", i+1, k, dp[i+1][k]);
          }
        }
      }
      if (mi > dp[6][0]) {
        ans = m+1;
        mi = dp[6][0];
      }
//      cout << dp[6][0] << endl;
    }
    printf("%d %d\n", (ans+4)%5, mi);
  }
}