#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <complex>

using namespace std;

#define INF 1 << 16

typedef complex<int> P;

int abs(int n) {
	return n < 0 ? -n : n;
}

int main() {
	int W, H;
	while (cin >> W >> H, W || H) {
		vector<P> v;
		vector<int> type;
		map< int, vector<int> > m;

		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x) {
				if (str[x] == '.') continue;

				v.push_back( P(x, y) );
				if (str[x] == 'S') type.push_back( -1 );
				else if (str[x] == 'G') type.push_back( -2 );
				else if (str[x] != '.') type.push_back( str[x] - '1' );

				m[type[type.size()-1]].push_back(v.size()-1);
			}
		}

		int f = false;
		for (int i = 0; i < 5; ++i)
			if ( !m[i].size() )
				f = true;

		if (f) {
			cout << "NA" << endl;
			continue;
		}

		vector< vector<int> > cost(v.size(), vector<int>(v.size(), INF));
		for (int i = 0; i < v.size(); ++i)
			for (int j = 0; j < v.size(); ++j)
				cost[i][j] = abs(v[i].real() - v[j].real()) + abs(v[i].imag() - v[j].imag());

		pair<int, int> ans = pair<int, int>(0, INF);
		for (int kind = 0; kind < 5; ++kind) {
			vector<int> len(v.size(), INF);

			vector<int> types;
			types.push_back(-1);
			for (int i = 0; i < 4; ++i)
				types.push_back( (kind + i + 1) % 5 );

			types.push_back(-2);

			len[m[-1][0]] = 0;
			for (int i = 0; i < 5; ++i) {
				int now = types[i], next = types[i+1];
				for (int j = 0; j < m[next].size(); ++j)
					for (int k = 0; k < m[now].size(); ++k)
						if (len[m[next][j]] > len[m[now][k]] + cost[m[now][k]][m[next][j]])
							len[m[next][j]] = len[m[now][k]] + cost[m[now][k]][m[next][j]];
			}

			if (len[m[-2][0]] < ans.second)
				ans = pair<int, int>(kind+1, len[m[-2][0]]);
		}

		cout << ans.first << " " << ans.second << endl;
	}
}