#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
using namespace std;

typedef pair<int, int> P;
const int INF = 1<<24;
const int N = 5;


vector<P> V[N+2];
vector<int> T[N+2];

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

int calc(int st) {
  for(int i = 0; i < N+2; ++i) T[i].clear();
  T[0].push_back(0);

  int bp = 0;
  for(int i = 1; i <= N; ++i) {
    int p;
    if(i == N) p = N+1;
    else       p = (st-1+i)%N+1;
    for(int j = 0; j < V[p].size(); ++j) {
      int minCost = INF;
      for(int k = 0; k < V[bp].size(); ++k) {
	minCost = min(minCost, T[bp][k] + dist(V[bp][k], V[p][j]));
      }
      T[p].push_back(minCost);
    }
    bp = p;
  }
  return T[N+1][0];
}

void solve() {
  int ans = INF;
  int ansi = -1;

  for(int i = 1; i <= N; ++i) {
    int newValue = calc(i);
    if(newValue < ans) {
      ans = newValue;
      ansi = i;
    }
  }
  if(ansi == -1) cout << "NA" << endl;
  else cout << ansi << " " << ans << endl;
}

int main() {
  int W, H;
  while(cin >> W >> H && (W || H)) {
    for(int i = 0; i < N+2; ++i) V[i].clear();
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	char c;
	cin >> c;
	if(c == 'S')      V[0].push_back(P(j,i));
	else if(c == 'G') V[N+1].push_back(P(j,i));
	else if(c != '.') V[c-'0'].push_back(P(j,i));
      }
    }
    solve();
  }
  return 0;
}