#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int INF = 100000000;

class P{
public:
  int x, y, c;
  P(int y = 0, int x = 0, int c = 0) : y(y), x(x), c(c) {}
};

int w, h;
vector<P> data[5];
P s, g;

int dist(P a, P b){
  return abs(a.y - b.y) + abs(a.x - b.x);
}

void solve(){
  int ans1, ans2 = INF;
  P dp[5][1000];

  for(int i=0;i<5;i++){
    /*for(int j=0;j<5;j++){
      for(int k=0;k<1000;k++){
        dp[j][k].c = INF;
      }
      }*/
    fill(dp[0], dp[5], P(0, 0, INF));
    int next = (i+1)%5;
    for(int j=0;j<data[next].size();j++){
      dp[next][j] = data[next][j];
      dp[next][j].c = dist(data[next][j], s);
    }
    for(int j=0;j<3;j++){
      next = (i+j+2)%5;
      int now = (next+4)%5;
      for(int k=0;k<data[now].size();k++){
        for(int l=0;l<data[next].size();l++){
          int tmp = dp[now][k].c + dist(dp[now][k], data[next][l]);
          if(dp[next][l].c > tmp){
            dp[next][l] = data[next][l];
            dp[next][l].c = tmp;
          }
        }
      }
    }
    next = (i+4)%5;
    for(int j=0;j<data[next].size();j++){
      int tmp = dp[next][j].c + dist(dp[next][j], g);
      if(ans2 > tmp){
        ans2 = tmp;
        ans1 = i+1;
      }
    }
  }
  if(ans2 == INF) cout << "NA" << endl;
  else cout << ans1 << ' ' << ans2 << endl;
}

main(){
  while(cin >> w >> h && (w|h)){
    for(int i=0;i<5;i++) data[i].clear();
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        char c;
        cin >> c;
        if(c == 'S'){
          s.y = i;
          s.x = j;
          s.c = 0;
        }else if(c == 'G'){
          g.y = i;
          g.x = j;
          g.c = 0;
        }else if(c != '.'){
          data[c-'1'].push_back(P(i, j, 0));
        }
      }
    }
    solve();
  }
}