#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cstdlib>
using namespace std;
#define rep(x,to) for(int x = 0; x <(to); ++(x))
typedef pair<int,int> pi;
int memo[1000][5];
int w,h;
string str;
int dist(pi &a, pi &b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

int main() { 
	while(cin >> w >> h && (w||h)) {
		pi s,g;
		vector<pi> f[5];
		rep(i,h) {
			cin >> str;
			rep(j,w) {
				if(str[j] == 'S') s = make_pair(i,j);
				else if(str[j] == 'G') g = make_pair(i,j);
				else if(str[j] == '1') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '2') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '3') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '4') f[str[j]-'1'].push_back(make_pair(i,j));
				else if(str[j] == '5') f[str[j]-'1'].push_back(make_pair(i,j));
			}
		}
		int ans = 1 << 30, ret = -1;

		rep(i,5) {
			rep(j,1000) {
				memo[j][i] = 1 << 30;
			}
			int cur = i, next = (i+1)%5;
			rep(j,f[next].size()) {
				memo[j][next] = dist(s, f[next][j]);
			}
			cur = next, next =(next+1)%5;
			rep(j,3) {
				rep(k,f[next].size()) {
					rep(l,f[cur].size()) {
						memo[k][next] = min(memo[k][next], memo[l][cur] + dist(f[cur][l], f[next][k]));
					}
				}
				cur = next, next = (next+1)%5;
			}
			rep(j,f[cur].size()) {
				int tmp = memo[j][cur] + dist(f[cur][j], g);
				if(tmp < ans) {
					ans = tmp, ret = i;
				}
			}
		}
		if(ans == 1<<30) cout << "NA" << endl;
		else cout << ret + 1 << " " << ans << endl;
	}
	return 0;
}