#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define f(a)(a==0?4:a-1)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

struct st {
	int x, y, a, c, s;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int d[1000][1000][1 << 5][5];
char c[1000][1001];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		int sx, sy, gx, gy;
		rep(i, h) {
			scanf("%s", c[i]);
			rep(j, w) {
				if ('1' <= c[i][j] && c[i][j] <= '5')c[i][j]--;
				if (c[i][j] == 'S')sx = i, sy = j;
				if (c[i][j] == 'G')gx = i, gy = j;
			}
		}
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		d[sx][sy][1 << 0][0] = 0; que.push({ sx,sy,1 << 0,0,0 });
		d[sx][sy][1 << 1][1] = 0; que.push({ sx,sy,1 << 1,0,1 });
		d[sx][sy][1 << 2][2] = 0; que.push({ sx,sy,1 << 2,0,2 });
		d[sx][sy][1 << 3][3] = 0; que.push({ sx,sy,1 << 3,0,3 });
		d[sx][sy][1 << 4][4] = 0; que.push({ sx,sy,1 << 4,0,4 });
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.x][p.y][p.a][p.s] != p.c)continue;
			rep(i, 4) {
				int nx = p.x + dx[i], ny = p.y + dy[i];
				if (!(0 <= nx&&nx < h && 0 <= ny&&ny < w))continue;
				int k;
				if ('0' <= c[nx][ny] && c[nx][ny] <= '4'&&p.a >> f(c[nx][ny] - '0') & 1)
					k = p.a | 1 << (c[nx][ny] - '0');
				else k = p.a;
				if (d[nx][ny][k][p.s] > p.c + 1) {
					d[nx][ny][k][p.s] = p.c + 1;
					que.push({ nx,ny,k,p.c + 1,p.s });
				}
			}
		}
		int Min = INF, id;
		rep(i, 5) {
			if (Min > d[gx][gy][(1 << 5) - 1][i]) {
				Min = d[gx][gy][(1 << 5) - 1][i];
				id = i + 1;
			}
		}
		if (Min == INF)puts("NA");
		else printf("%d %d\n", id, Min);
	}
}