#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


using namespace std;

#define X first
#define Y second

inline int manh_dist(pair<int,int> &s, pair<int,int> &g){
	return abs(s.X - g.X) + abs(s.Y - g.Y);
}


int main(void){
	int n,m;
	char c;
	while(cin >> m >> n){
		if(!(n|m)) break;
		vector<pair<int,int> > nodes[5];
		pair<int,int> s,g;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin >> c;
				if(c == 'S'){
					s.X = i;
					s.Y = j;
				}else if(c == 'G'){
					g.X = i;
					g.Y = j;
				}else if(c == '.'){
				}else{
					nodes[c-'0'-1].push_back(make_pair(i,j));
				}
			}
		}
				
		int ret = 1 << 28;
		int tmp_min;
		int attr = -1;
		for(int i=0;i<5;i++){ //i:ツ堕ョツ青ォ
			//cout << 1 << endl;
			int dp[5][1000];
			fill((int *)dp, (int *)dp+5*1000, 1<<28);
			tmp_min = 1 << 28;
			
			//sツつゥツづァツつスツづづィツ陳つッツづゥツ堕ョツ青ォツづ個値ツづーツ更ツ新
			for(int j=0;j<nodes[(i+1)%5].size();j++){
				dp[(i+1)%5][j] = min(dp[(i+1)%5][j], manh_dist(s, nodes[(i+1)%5][j]));
			}
			//ツ篠淞づ個堕ョツ青ォツ暗按古」ツづーツ計ツ算ツつオツづつ「ツつュ
			for(int cur = (i+1)%5; cur != i; cur = (cur+1)%5){
				int next = (cur+1)%5;
				for(int p=0;p<nodes[cur].size();p++){
					for(int q=0;q<nodes[next].size();q++){
						dp[next][q] = min(dp[next][q], dp[cur][p] + manh_dist(nodes[cur][p], nodes[next][q]));
					}
				}
			}
			int end = i-1;
			if(end < 0) end = 4;
			//ツ催古」ツづ個要ツ素ツつゥツづァGツづ慊づづ個仰猟猟」ツづーツ嘉鳴。ツつオツづ計ツ算
			for(int j=0;j<nodes[end].size();j++){
				tmp_min = min(tmp_min, dp[end][j]+manh_dist(g, nodes[end][j]));
			}
			if(ret > tmp_min){
				ret = tmp_min;
				attr = i;
			}
		}
		if(attr == -1){
			cout << "NA" << endl;
		}else{
			cout << (attr+1)%5 << " " << ret;
		}
	}
}