#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int b[1010][1010];
bool v[1010][1010];
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int x,y,sx,sy,gx,gy;
string st;
const int INF = 99999999;
struct S {
	int x, y, t;
};
int bfs(int a) {
	int c = a;
	queue<S> q;
	S s = {sx,sy,0};
	q.push(s);
	bool f = 1;
	while(!q.empty()) {
		S cs = q.front();
		v[cs.y][cs.x] = 1;
		if(!f && cs.x==gx && cs.y==gy) break;
		q.pop();
		if(f && b[cs.y][cs.x]==(c+1)%5) {
			if(c==(a+5-2)%5) f = 0;
			else c = (c+1)%5;
			rep(i,1010) {
				rep(j,1010) {
					v[i][j] = 0;
				}
			}
			queue<S> nq;
			nq.push(cs);
			q = nq;
		}
		rep(i,4) {
			int ax = cs.x+dx[i], ay = cs.y+dy[i];
			if(b[ay][ax]==-2 || v[ay][ax]) continue;
			S ns = {ax,ay,cs.t+1};
			q.push(ns);
		}
	}
	if(q.empty()) return INF;
	else return q.front().t;
}
int main(){
	while(cin >> x >> y, (x || y)) {
		rep(i,1010) {
			rep(j,1010) {
				b[i][j] = -1;
			}
		}
		rep(i,y+2) {
			b[i][0] = -2;
			b[i][x+1] = -2;
		}
		rep(i,x+2) {
			b[0][i] = -2;
			b[y+1][i] = -2;
		}
		rep(i,y) {
			cin >> st;
			rep(j,x) {
				if(st[j]=='.') continue;
				else if(st[j]=='S') sx=j+1, sy=i+1;
				else if(st[j]=='G') gx=j+1, gy=i+1;
				else b[i+1][j+1] = (st[j]-'0') - 1;
			}
		}
		int ret = INF, ans = -1;
		rep(i,5) {
			rep(i,1010) {
				rep(j,1010) {
					v[i][j] = 0;
				}
			}
			int x = bfs(i);
			if(x < ret) ret = x, ans = i;
		}
		if(ans==-1) cout << "NA" << endl;
		else cout << ans+1 << " " << ret << endl;
	}
}