#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
using namespace std;


int W,H;
int sx,sy,gx,gy;
vector< pair<int,int> > e[5];
map< pair< pair<int,int> , pair<int,int> > , int > memo; 
int dfs(int x,int y,int c,int r){
	if( memo.count(make_pair(make_pair(x,y),make_pair(c,r))) )
		return memo[make_pair(make_pair(x,y),make_pair(c,r))];
	if( r == 0 ) return abs(gx-x)+abs(gy-y);
	int g = (c+1)%5;
	int ans = 1e8;
	for(int i = 0 ; i < e[g].size() ; i++){
		ans = min( ans , dfs(e[g][i].first,e[g][i].second,g,r-1) + abs(e[g][i].first-x)+abs(e[g][i].second-y) );
	}
	return memo[make_pair(make_pair(x,y),make_pair(c,r))] = ans;
}
int main(){
	while(cin >> W >> H && W){
		rep(i,5)e[i].clear();
		sx = sy = gx = gy = 1e7;
		
		rep(i,H){
			rep(j,W){
				char c;
				cin >> c;
				if( c == 'S' ) sx = j , sy = i;
				else if( c == 'G' ) gx = j , gy = i;
				else if( c != '.' ) e[c-'1'].push_back(make_pair(j,i));
			}
		}
		int F = !e[0].size() + !e[1].size() + !e[2].size() + !e[3].size() + !e[4].size();
		if( F >= 2){
			cout << "NA" << endl;
			continue;
		}
		pair<int,int> ans = make_pair(1e8,1e8);
		rep(i,5){
			memo.clear();
			ans = min(ans,make_pair(dfs(sx,sy,i,4),i));
		}
		if( 1e6 > ans.first ){
			cout << ans.second+1 << " " << ans.first << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}