#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 dp[6][1000];
vector<pii> pati[7];

int dist(pii p1, pii p2) {
	return abs(p1.fi - p2.fi) + abs(p1.se - p2.se);
}

int main() {
	while (cin >> W >> H, W || H) {
		REP(i, H) cin >> maps[i];
		
		REP(i, 8) pati[i].clear();
		REP(i, H) REP(j, W) {
			int idx = -1;
			if (maps[i][j] == 'S') idx = 0;
			if (maps[i][j] == 'G') idx = 6;
			if (isdigit(maps[i][j])) idx = maps[i][j] - '1' + 1;
			if (~idx) pati[idx].push_back(pii(i, j));
		}
		
		pii ans = pii(INF, -1);
		
		REP(t, 5) { // start patimon
			fill(dp[0], dp[6], INF);
			
			dp[0][0] = 0;
			int now = 0;
			REP(k, 5) {
				int next;
				if (k == 0) next = (t + 1) % 5 + 1;
				else if (k == 4) next = 6;
				else next = now % 5 + 1;
				
				REP(i, pati[now].size()) {
					REP(j, pati[next].size()) {
						chmin(dp[k + 1][j], dp[k][i] + dist(pati[now][i], pati[next][j]));
					}
				}
				
				now = next;
			}
			
			chmin(ans, pii(dp[5][0], t + 1));
		}
		
		if (ans.se == -1) puts("NA");
		else printf("%d %d\n", ans.se, ans.fi);
	}
	
	return 0;
}