#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF (1<<25)
int X,Y;
int sx,sy,gx,gy;

int x[5][1000];
int y[5][1000];
int memo[1000][5][5];
int sz[5];

int f(int w,int z,int s){
	if((z+1)%5==s) return abs(x[z][w]-gx)+abs(y[z][w]-gy);
	if(~memo[w][z][s]) return memo[w][z][s];
	int ans = INF;
	for(int i = 0 ; i < sz[(z+1)%5] ; i++){
		ans = min(ans,f(i,(z+1)%5,s)+abs(x[z][w]-x[(z+1)%5][i])+abs(y[z][w]-y[(z+1)%5][i]));
	}
	return memo[w][z][s] = ans;
}
int main(){
	while(cin >> X >> Y && X){
		memset(memo,-1,sizeof(memo));
		for(int i = 0 ; i < 5 ; i++) sz[i]=0;
		
		for(int i = 0 ; i < Y ; i++)
			for(int j = 0 ; j < X ; j++){
				char c; scanf(" %c",&c);
				if(c == 'S'){
					sx = j , sy = i;
				}else if( c == 'G'){
					gx = j , gy = i;
				}else if( c != '.'){
					c = c - '1';
					x[c][sz[c]] = j;
					y[c][sz[c]++] = i;			
				}
			}
		pair<int,int> ans(INF,-1);
		for(int i = 0 ; i < 5 ; i++){
			for(int j = 0 ; j < sz[(i+1)%5] ; j++){
				ans = min(ans,make_pair(abs(sx-x[(i+1)%5][j])+abs(sy-y[(i+1)%5][j])+f(j,(i+1)%5,i),i));
			}
		}
		if(~ans.second)cout << ans.second+1 << " " << ans.first << endl;
		else cout << "NA" << endl;
	}
		
}