#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

typedef pair<int,int> pos;

const int infty = 1<<29;

int MHdist(pos A, pos B){
  return abs(A.first-B.first)+abs(A.second-B.second);
}

int solve( int start,
	   vector< vector< pair<pos,int> > > & PM,
	   const pos &S,
	   const pos &G ){

  int end = (start + 3) % 5;

  // cout << "START : " << start << " END : " << end << endl;
  int ret = infty;

  for(int i = 0; i < PM.size(); ++i){
    for(int j = 0; j < PM[i].size(); ++j){
      PM[i][j].second = infty;
    }
  }
  
  for(int i = 0; i < PM[start].size(); ++i){
    PM[start][i].second = MHdist( S, PM[start][i].first );
  }
  
  for(int k = 1; k < 5; ++k){
    int now = (start + k) % 5;
    int prev = (now + 4) % 5;
    //cout << " NOW : " << now << " PREV : " << prev << endl;
    for(int i = 0; i < PM[now].size(); ++i){
      
      int minimum = infty;
      for(int j = 0; j < PM[prev].size(); ++j){
	minimum = min( minimum,
		       PM[prev][j].second + MHdist( PM[prev][j].first, PM[now][i].first) );
      }
      
      //cout << minimum << endl;
      PM[now][i].second = min( PM[now][i].second, minimum );
      //cout << PM[now][i].second << endl;
    }
  }

  for(int i = 0; i < PM[end].size(); ++i){
    ret = min( ret, PM[end][i].second + MHdist( PM[end][i].first, G ) );
  }

  return ret;
}

int main()
{
  while(true){
    int ans_st;
    int ans = infty;
    int W,H;
    pos S,G;
    vector< vector< pair<pos,int> > > pachi(5);

    cin >> W >> H;
    if( W == 0 && H == 0 ) break;
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	char c;
	cin >> c;
	if( c == 'S' ) S = pos(i,j);
	else if( c == 'G' ) G = pos(i,j);
	else if( c == '.' ) continue;
	else pachi[c-'0'-1].push_back( make_pair(pos(i,j),infty) );
      }
    }
    for(int i = 0; i < 5; ++i){
      int t = solve( i, pachi, S, G );
      if( ans > t ){
	ans_st = i;
	ans = t;
      }
    }

    if( ans >= infty )
      cout << "NA" << endl;
    else
      cout << ans_st << ' ' << ans << endl;
  }
  return 0;
}