#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

struct st {
	int p, a, c, s;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int d[5001][1 << 5][5], x[5001], y[5001], len[5], t[5][1001];
char c[1001];

int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		int sx, sy, gx, gy, s = 0;
		memset(len, 0, sizeof(len));
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		rep(i, h) {
			scanf("%s", c);
			rep(j, w) {
				if ('1' <= c[j] && c[j] <= '5') {
					c[j] -= '1'; len[c[j]]++;
					t[c[j]][len[c[j]]] = ++s;
					x[s] = i; y[s] = j;
				}
				if (c[j] == 'S') {
					x[0] = i; y[0] = j;
					rep(k, 5) {
						d[0][1 << k][k] = 0;
						que.push({ 0,1 << k,0,k });
					}
				}
				if (c[j] == 'G')gx = i, gy = j;
			}
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.p][p.a][p.s] != p.c)continue;
			rep(i, 5) {
				if ((p.a >> i & 1) || !(p.a >> ((i + 4) % 5) & 1))continue;
				for (int j = 1; j <= len[i]; j++) {
					int&o = d[t[i][j]][p.a | 1 << i][p.s],
						u = p.c + abs(x[p.p] - x[t[i][j]]) + abs(y[p.p] - y[t[i][j]]);
					if (o > u) {
						o = u; que.push({ t[i][j],p.a | 1 << i,o,p.s });
					}
				}
			}
		}
		int Min = INF, id;
		rep(i, s + 1) {
			rep(j, 5) {
				int cost = d[i][(1 << 5) - 1][j] + abs(x[i] - gx) + abs(y[i] - gy);
				if (cost < Min)Min = cost, id = j + 1;
				else if (cost == Min)id = min(id, j + 1);
			}
		}
		if (Min == INF)puts("NA");
		else printf("%d %d\n", id, Min);
	}
}