#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int L = 5;
const int MAX_H = 1010;
const int MAX_W = 1010;
const int INF = 1e9 + 7;

class C{
  public:
    int y, x, cnt, fir, bit;
    C(){}
    C(int yy, int xx, int cc, int ff, int bb) { y = yy; x = xx; cnt = cc; fir = ff; bit = bb; }
};

int W, H;
int my[] = {0, 0, 1, -1};
int mx[] = {1, -1, 0, 0};
int closed[MAX_H][MAX_W][(1 << L)];

bool check(int bit, int m){
  int tar = (m == 0 ? 4 : m - 1);
  if(bit & (1 << tar)) return true;
  return false;
}

P solve(int sy, int sx, int gy, int gx, vector< vector<int> > &v){
  queue<C> open;
  REP(i, MAX_H) REP(j, MAX_W) REP(k, L) REP(l, (1 << L)) closed[i][j][k][l] = INF;
  //REP(i, L){
  //  open.push(C(sy, sx, 0, i, (1 << i)));
  //  closed[sy][sx][i][(1 << i)] = 0;
  //}
  //while(!open.empty()){
  //  C c = open.front(); open.pop();
  //  REP(i, 4){
  //    int ny = c.y + my[i], nx = c.x + mx[i];
  //    if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
  //    int nb = c.bit;
  //    if(v[ny][nx] != -1 && check(c.bit, v[ny][nx])) nb |= (1 << v[ny][nx]);
  //    if(closed[ny][nx][c.fir][nb] <= c.cnt + 1) continue;
  //    closed[ny][nx][c.fir][nb] = c.cnt + 1;
  //    open.push(C(ny, nx, c.cnt + 1, c.fir, nb));
  //  }
  //}
  P res = P(INF, INF);
  //REP(i, L) if(closed[gy][gx][i][(1 << L) - 1] < res.second) res = P(i + 1, closed[gy][gx][i][(1 << L) - 1]);
  return res;
}

int main() {
  while(cin >>W >>H && W && H){
    int sy, sx, gy, gx;
    vector< vector<int> > v(H, vector<int>(W));
    REP(i, H){
      REP(j, W){
        char c; cin >>c;
        if(c == 'S') { sy = i; sx = j; v[i][j] = -1; }
        else if(c == 'G') { gy = i; gx = j; v[i][j] = -1; }
        else if(c == '.') { v[i][j] = -1; }
        else { v[i][j] = c - '0' - 1; }
      }
    }
    P res = solve(sy, sx, gy, gx, v);
    if(res.first == INF) cout <<"NA" <<endl;
    else cout <<res.first <<" " <<res.second <<endl;
  }
  return 0;
}