#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
struct P{int x,y,cost;};
#define rep(i,n) for(int i=0; i<n ;i++)

int dist(P a,P b){
	return abs(a.x-b.x) + abs(a.y-b.y);
}
int main(){
	int w,h;
	
	while(cin >> w >> h , w) {
		vector<P> data[5];
		P start , goal ;
		
		rep(i,h)rep(j,w){
			char c;	cin >> c;
			if(c != '.'){
				if(c == 'S'){
					start.x = j , start.y = i;
				}else if(c == 'G'){
					goal.x = j , goal.y = i;
				}else{
					P t = {j,i};
					data[c-'1'].push_back(t);
				}
			}
		}
		
		pair<int,int> ret = make_pair((1<<23),10);
		
		P dp[5][1000];
		rep(i,5)rep(j,5){
			dp[i][j].cost = (1<<25);
		}
		rep(lp,5){ // start 
			rep(i,data[lp].size()){
				dp[0][i] = data[lp][i];
				dp[0][i].cost = dist(start,data[lp][i]);
			}			
			rep(Z,4){ //kurikaesi
				int z = (lp+Z+1)%5;
				rep(i,data[(z+4)%5].size()){ // izen
					rep(j,data[z].size()){ //now
						int cost = dp[(z+4)%5][i].cost + dist(dp[(z+4)%5][i],data[z][j]);
						if(dp[z][j].cost > cost){
							dp[z][j] = data[z][j];
							dp[z][j].cost = cost;
						}
					}
				}
				int mincost = (1<<25);
				rep(i,data[(lp+4)%5].size() ){
					mincost = min(mincost,dp[(lp+4)%5][i].cost + dist(dp[(lp+4)%5][i],goal));
				}
				ret = min(make_pair(mincost,lp),ret);
			}
			
		}
		
		if(ret.first == (1<<23))cout << "NA" << endl; 
		else cout << ret.second+1 << " " << ret.first << endl; 
	}
}