#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath> 
using namespace std;

const int MAX_N = 1000;
const int INF = 1e+8;

struct Point{
	int x, y;
	Point(int x_, int y_){
		x = x_; y = y_;
	}
	Point(){}
};

int H, W, sy, sx, gy, gx, cnt[5];
Point P[5][MAX_N];

int dist(int x1, int y1, int x2, int y2){
	return abs(x1-x2) + abs(y1-y2);
}  

pair<int,int> solve(){
	int t;
	pair<int,int> result;
	result.second = INF;
	
	int dp[5][MAX_N];
	for(int s=0 ; s < 5 ; s++ ){  
		for(int i=0 ; i < 5 ; i++ ){
			for(int j=0 ; j < cnt[i] ; j++ ){
				dp[i][j] = INF;
			}
		}
		t = (s+1) % 5;
		for(int j=0 ; j < cnt[t] ; j++ ){
			dp[t][j] = dist(sx, sy, P[t][j].x, P[t][j].y );
		}
		for(int i = s+1 ; i < s + 5 ; i++ ){  
			int b = i % 5;
			int e = (i+1) % 5;
			for(int k=0 ; k < cnt[b] ; k++ ){
				for(int l=0 ; l < cnt[e] ; l++ ){
					int d = dist(P[b][k].x, P[b][k].y, P[e][l].x, P[e][l].y);
					dp[e][l] = min( dp[e][l] , dp[b][k] + d );
				}
			}
		}
		t = (s+4) % 5;
		for(int j=0 ; j < cnt[t] ; j++ ){
			int d = dist(gx, gy, P[t][j].x, P[t][j].y );
			if( dp[t][j] + d < result.second ){
				result.second = dp[t][j] + d;
				result.first = s;
			}
		}
	}
	return result; 
}

int main(){
	while( cin >> W >> H , W || H ){
		for(int i=0 ; i < 5 ; i++ ){
			cnt[i] = 0;
		}
		for(int y=0 ; y < H ; y++ ){
			for(int x=0 ; x < W ; x++ ){
				char ch;
				cin >> ch;
				if( ch == '.' ) continue;
				
				if( ch == 'S' ){
					sy = y; sx = x;  
				}else if( ch == 'G' ){
					gy = y; gx = x;
				}else{
					int k = ch -'0' - 1;
					P[k][ cnt[k] ] = Point(x,y);
					cnt[k]++;
				}
			}
		}
		pair<int,int> ans = solve();
		if( ans.second == INF ){
			cout << "NA" << endl;
		}else{
			cout << ans.first+1 << " " << ans.second << endl;
		}
	}  
}