// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<queue>

#include<vector>

#include<queue>

#define INF 99999999

using namespace std;

typedef pair<int, int> P;

vector<P> point[7];

int x,y;

int dp[6][1001][6];

char mas[1001][1001];

int cx[6],ans;

int sp,ans1;

int solve(int i , int j, int z);

int main(){

  while(1){

    for(int i = 0; i < 7; i++){

      point[i].clear();

    }

    memset(cx, 0, sizeof(cx));

    ans1 = INF;

    sp = INF;

    cin >> x >> y;

    if(x == 0 && y == 0) break;

    for(int i = 0; i < y; i++) cin >> mas[i];

    for(int i = 0; i < y; i++){ 

      for(int j = 0; j < x; j++){

    if(mas[i][j] == 'S'){

      point[0].push_back(P(j,i));

    }

    if(mas[i][j] == 'G'){

      point[6].push_back(P(j,i));

    }

    if(mas[i][j] >= '1' && mas[i][j] <= '5'){

      point[mas[i][j] - '0'].push_back(P(j,i));

      cx[mas[i][j] - '0']++;

    }

      }

    }

    for(int i = 1; i <= 5; i++){

      rotate(point + 1, point + 2, point + 6);

      rotate(cx + 1, cx + 2, cx + 6);

      memset(dp, -1, sizeof(dp));

      ans = solve(0, 0, 0);

      if(ans < ans1){

    ans1 = ans;

    sp = i;

      }

    }

    if(ans1 == INF) cout << "NA" << endl;

    else cout << sp << " " << ans1 << endl;

  }

}

int solve(int i, int j,int z){

  if(dp[i][j][z] >= 0) return dp[i][j][z];

  if(i == 4){

    return abs(point[6][0].first - point[z][j].first) + abs(point[6][0].second - point[z][j].second);

  }

  int res = INF;

  for(int k = 0; k < cx[z + 1]; k++){

    res = min(abs(point[z + 1][k].first - point[z][j].first) + abs(point[z + 1][k].second - point[z][j].second) + solve(i + 1, k, z + 1),res);

  }

  return dp[i][j][z] = res;

}

// Faster C++ solution for the same problem (measured speedup: 1.232527328152444x):
#include<cstdio>

#include<vector>

#include<map>

#include<algorithm>

#include<cstring>

#define INF 1<<28

#define F first

#define S second

using namespace std;

  

int sx, sy, gx, gy;

typedef pair < int, int > P;

vector < P > v[5];

int memo[5][5][1111];

 

int dist(P a, P b){

  return abs(a.F - b.F) + abs(a.S - b.S);

}

 

 

int solve(int cnt, int now, int p){

  

  if(cnt == 4) return dist(v[now][p], P(gx, gy));

  if(~memo[cnt][now][p]) return memo[cnt][now][p];

  

  int ans = INF, next = (now+1)%5, cost;

  for(int i=0;i<v[next].size();i++){

    if(!cnt) cost = dist(P(sx, sy), v[next][i]);

    else cost = dist(v[now][p], v[next][i]);

    ans = min(ans, solve(cnt+1, next, i) + cost);

  }

  

  return memo[cnt][now][p] = ans;

}

  

int main(){

  

  int w, h;

  char c;

  

  while(scanf("%d %d", &w, &h), w){

     

    for(int i=0;i<5;i++) v[i].clear();

     

    for(int i=0;i<h;i++){

      for(int j=0;j<w;j++){

    scanf(" %c", &c);

    if(c == '.') continue;

    else if(c == 'S') sx = j, sy = i;

    else if(c == 'G') gx = j, gy = i;

    else v[c-'1'].push_back( P(j,i) );

      }

    }

     

    int a, b = INF;

    memset(memo, -1, sizeof(memo));

    for(int i=0;i<5;i++){

      if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0);

    }

  

    b == INF?puts("NA"):printf("%d %d\n", a, b);

  

  }

}