#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;

int w, h;
vector<pair<int, int> > b[7];
vector<pair<int, int> > v[6];

int dist(pair<int, int> p1, pair<int, int> p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int dp[6][1000];

void solve()
{
	v[0] = b[0];
	v[5] = b[6];
	
	pair<int, int> res(INF, INF);
	
	for (int fi = 1; fi <= 5; fi++){
		for (int i = 1; i <= 4; i++){
			int x = (fi + i - 1) % 5 + 1;
			v[i] = b[x];
		}
		
		fill((int*)dp, (int*)dp + 6000, INF);
		dp[0][0] = 0;
		
		for (int i = 0; i < 6; i++){
			for (int j = 0; j < v[i].size(); j++){
				for (int k = 0; k < v[i + 1].size(); k++){
					dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + dist(v[i][j], v[i + 1][k]));
				}
			}
		}
		
		res = min(res, make_pair(dp[5][0], fi));
	}
	
	if (res.first == INF) puts("NA");
	else printf("%d %d\n", res.second, res.first);
}

int main()
{
	char c;
	while (scanf("%d %d", &w, &h), w){
		for (int i = 0; i < 7; i++){
			b[i].clear();
		}
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				pair<int, int> p(i, j);
				scanf(" %c", &c);
				switch (c){
					case 'S':
					b[0].push_back(p);
					break;
					
					case 'G':
					b[6].push_back(p);
					break;
					
					case '.':
					break;
					
					default:
					b[c - '0'].push_back(p);
				}
			}
		}
		solve();
	}
}