#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int W, H;
string maps[1000];
int d[36][1000][1000];

int main() {
	while (cin >> W >> H, W || H) {
		REP(i, H) cin >> maps[i];
		
		int sx, sy, gx, gy;
		REP(i, H) REP(j, W) {
			if (maps[i][j] == 'S') sx = j, sy = i;
			if (maps[i][j] == 'G') gx = j, gy = i;
		}
		
		pii ans(INF, INF);
		
		REP(k, 36) REP(i, H) REP(j, W) d[k][i][j] = INF;
		
		queue<pip> que;
		que.push(pip(0, pii(sy, sx)));
		d[0][sy][sx] = 0;
		
		while (!que.empty()) {
			pip now = que.front(); que.pop();
			int x = now.se.se, y = now.se.fi;
			int num = now.fi;
			
			if (ans.se <= num / 6) continue;
			
			char gl;
			if (num % 6 < 4) gl = (num / 6 + num % 6) % 5 + '1';
			else gl = 'G';
			
			int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
			REP(i, 4) {
				int nx = x + dx[i], ny = y + dy[i];
				if (!(nx >= 0 && nx < W && ny >= 0 && ny < H)) continue;
				
				if (num == 0) {
					if (isdigit(maps[ny][nx])) {
						int nextnum = ((maps[ny][nx] - '1' + 4) % 5 + 1) * 6 + 1;
						if (chmin(d[nextnum][ny][nx], d[0][y][x] + 1)) que.push(pip(nextnum, pii(ny, nx)));
					}
					if (chmin(d[num][ny][nx], d[num][y][x] + 1)) que.push(pip(num, pii(y, x)));
				}
				else {
					if (maps[ny][nx] == gl && chmin(d[num + 1][ny][nx], d[num][y][x] + 1)) {
						if (num % 6 < 4) que.push(pip(num + 1, pii(ny, nx)));
						else chmin(ans, pii(d[num + 1][ny][nx], num / 6));
					}
					else if (chmin(d[num][ny][nx], d[num][y][x] + 1)) que.push(pip(num, pii(ny, nx)));
				}
			}
		}
		
		if (ans.se == INF) puts("NA");
		else printf("%d %d\n", ans.se, ans.fi);
	}
	return 0;
}