#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#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()

#define MAX (10000000)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int memo[1001][1001][5];

int sx, sy;
int gx, gy;
vector<int> px[5];
vector<int> py[5];

#define ABS(x) ((x) < 0 ? -(x) : (x))
inline int dist(int x1, int x2, int y1, int y2){
  return ABS(x1 - x2) + ABS(y1 - y2);
}

int dp(int x, int y, int now, int last){
  if(now == last){
    return memo[x][y][now] = dist(x, gx, y, gy);
  }
  if(memo[x][y][now] != MAX) return memo[x][y][now];
  int ret = MAX;
  int n = px[now].size();
  REP(i, n){
    int d = dist(x, px[now][i], y, py[now][i]);
    int tmp = d + dp(px[now][i], py[now][i], (now+1)%5, last);
    ret = min(ret, tmp);
  }
  return memo[x][y][now] = ret;
}

int main(){
  int w,h;
  while(scanf("%d%d ",&w,&h), w+h){
    REP(i,5) px[i] = vector<int>();
    REP(i,5) py[i] = vector<int>();
    REP(i,h) REP(j,w){
      char tmp;
      scanf("%c ",&tmp);
      if(isdigit(tmp)){
        px[tmp- '1'].push_back(j);
        py[tmp- '1'].push_back(i);
      }else if(tmp == 'S'){
        sx = j;
        sy = i;
      }else if(tmp == 'G'){
        gx = j;
        gy = i;
      }
    }
    int ans = MAX;
    int type = -1;
    REP(s,5){
      int x = sx;
      int y = sy;
      REP(xx,w+1) REP(yy,h+1) REP(i,5) memo[xx][yy][i] = MAX;
      int ret = dp(x, y, (s+1)%5, s);
      if(ans > ret){
        ans = ret;
        type = s;
      }
    }
    if(ans == MAX){
      puts("NA");
    }else{
      printf("%d %d\n",type+1,ans);
    }
  }
  return 0;
}