#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
#pragma warning(disable:4996)
vector<pair<int, int>>x[7], y[7]; int H, W; char S[1005];
vector<int>dp[7];
int main() {
	while (true) {
		cin >> W >> H; for (int i = 0; i < 7; i++)x[i].clear(); if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			scanf("%s", &S);
			for (int j = 0; j < W; j++) {
				if (S[j] == 'S') { x[0].push_back(make_pair(i, j)); }
				if (S[j] >= '1' && S[j] <= '5') { x[S[j] - '0'].push_back(make_pair(i, j)); }
				if (S[j] == 'G') { x[6].push_back(make_pair(i, j)); }
			}
		}
		int minx = 999999999, minid = -1;
		for (int i = 0; i < 5; i++) {
			vector<pair<int, int>>H = x[1]; x[1].clear(); x[1].push_back(x[0][0]);
			for (int j = 0; j < 7; j++) {
				dp[j].resize(x[j].size());
				for (int k = 0; k < dp[j].size(); k++)dp[j][k] = 999999999;
			}
			dp[1][0] = 0;
			for (int j = 2; j < 7; j++) {
				for (int k = 0; k < x[j - 1].size(); k++) {
					for (int l = 0; l < x[j].size(); l++) {
						int d = abs(x[j - 1][k].first - x[j][l].first) + abs(x[j - 1][k].second - x[j][l].second);
						dp[j][l] = min(dp[j][l], dp[j - 1][k] + d);
					}
				}
			}
			x[1] = H;
			for (int j = 1; j <= 5; j++)y[j] = x[j];
			for (int j = 1; j <= 5; j++)x[j] = y[j % 5 + 1];
			if (minx > dp[6][0]) { minx = dp[6][0]; minid = i + 1; }
		}
		if (minx == 999999999)cout << "NA" << endl;
		else cout << minid << ' ' << minx << endl;
	}
	return 0;
}