#include<iostream>
#include<queue>
#include<tuple>
using namespace std;
queue<tuple<int, int, int, int> >Q; bool x[1020][1020][6]; int H, W, p[1020][1020], sx, sy, gx, gy;
int main() {
	while (true) {
		for (int i = 0; i < 1020; i++) {
			for (int j = 0; j < 1020; j++) { p[i][j] = -1; for (int k = 0; k < 6; k++)x[i][j][k] = false; }
		}
		cin >> H >> W; int minx = 1 << 30, minid = 0; if (H == 0 && W == 0)break;
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				char v; cin >> v; if (v == 'S') { sx = i; sy = j; p[i][j] = 10; }
				else if (v == 'G') { gx = i; gy = j; p[i][j] = 10; }
				else if (v == '.') { p[i][j] = 10; }
				else { p[i][j] = (int)(v - '1'); }
			}
		}
		int dx[4] = { 0,-1,0,1 }, dy[4] = { 1,0,-1,0 };
		for (int t = 0; t < 5; t++) {
			for (int i = 0; i <= H; i++) {
				for (int j = 0; j <= W; j++) { for (int k = 0; k < 6; k++)x[i][j][k] = false; }
			}
			int res = 1 << 30; Q.push(make_tuple(sx, sy, 0, 0)); x[sx][sy][0] = true;
			while (!Q.empty()) {
				int a1 = get<0>(Q.front()), a2 = get<1>(Q.front());
				int a3 = get<2>(Q.front()), a4 = get<3>(Q.front()); Q.pop();
				if (a1 == gx && a2 == gy && a3 == 5) { if (res > a4)res = a4; }
				for (int i = 0; i < 4; i++) {
					int cx = a1 + dx[i], cy = a2 + dy[i]; if (p[cx][cy] == -1)continue;
					if (x[cx][cy][a3] == false) { Q.push(make_tuple(cx, cy, a3, a4 + 1)); x[cx][cy][a3] = true; }
					if (p[cx][cy] < 9) {
						int I = a3; if (p[cx][cy] - t <= a4 + 1)I++;
						if (x[cx][cy][I] == false) { Q.push(make_tuple(cx, cy, I, a4 + 1)); x[cx][cy][I] = true; }
					}
				}
			}
			if (minx > res) { minx = res; minid = t; }
		}
		if (minx < 1000000000) { cout << minid + 1 << ' ' << minx << endl; }
		else { cout << "NA" << endl; }
	}
	return 0;
}