#include<iostream>
#include<queue>
#include<cstdio>
#pragma warning(disable : 4996)
using namespace std;
int H, W; int dp[1003][1003][5];
int x[1003][1003]; char G[1111];
pair<int, short> Q[6000000];
int sx = 0, sy = 0, gx = 0, gy = 0;
inline int searching() {
	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			for (int k = 0; k < 5; k++)dp[i][j][k] = 1 << 30;
		}
	}
	Q[0] = make_pair(sx * 10000 + sy, 0); int L = 0, R = 1;
	int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; dp[sx][sy][0] = 0;
	while (L < R) {
		pair<int, int>E = Q[L]; L++;
		int cx = E.first / 10000, cy = E.first % 10000, F = E.second;
		for (int i = 0; i < 4; i++) {
			int fx = cx + dx[i], fy = cy + dy[i];
			int V1 = F; if (x[fx][fy] == F + 2)V1 += 1;
			if (dp[fx][fy][V1] > dp[cx][cy][F] + 1) {
				dp[fx][fy][V1] = dp[cx][cy][F] + 1;
				Q[R] = make_pair(fx * 10000 + fy, V1); R++;
			}
		}
	}
	return dp[gx][gy][4];
}
int main() {
	while (true) {
		scanf("%d%d", &W, &H); if (H == 0 && W == 0)break;
		for (int i = 0; i < H + 3; i++) {
			for (int j = 0; j < W + 3; j++)x[i][j] = -1;
		}
		for (int i = 1; i <= H; i++) {
			scanf("%s", G);
			for (int j = 1; j <= W; j++) {
				if (G[j - 1] > '0' && G[j - 1] < '6')x[i][j] = G[j - 1] - '0';
				else {
					x[i][j] = 0;
					if (G[j - 1] == 'S') { sx = i; sy = j; }
					if (G[j - 1] == 'G') { gx = i; gy = j; }
				}
			}
		}
		int minx = 100000000, minid = 0;
		for (int i = 0; i < 5; i++) {
			int p = searching();
			if (minx > p) { minx = p; minid = i + 1; }
			if (i == 4)continue;
			for (int j = 1; j <= H; j++) {
				for (int k = 1; k <= W; k++) {
					if (x[j][k] >= 1) {
						x[j][k]--; if (x[j][k] == 0)x[j][k] = 5;
					}
				}
			}
		}
		if (minx > 100000)cout << "NA" << endl;
		else { cout << minid << ' ' << minx << endl; }
	}
	return 0;
}