#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


pint node[5][1024];
int dp[5][1024];
int size[5];
int manha(const pint& a, const pint& b)
{
	return abs(a.first-b.first) + abs(a.second-b.second);
}
int main()
{
	int w, h;
	while (scanf("%d%d", &w, &h), w|h)
	{
		memset(size, 0, sizeof(size));

		pint start, goal;
		for (int y = 0; y < h; ++y)
		{
			char buf[128];
			scanf("%s", buf);
			for (int x = 0; x < w; ++x)
			{
				if (isdigit(buf[x]))
				{
					int attr = buf[x] - '0' - 1;
					node[attr][size[attr]++] = pint(x, y);
				}
				else if (buf[x] == 'S')
					start = pint(x, y);
				else if (buf[x] == 'G')
					goal = pint(x, y);
			}
		}

		int attrs = 0;
		int no_attr;
		for (int i = 0; i < 5; ++i)
		{
			if (size[i])
				++attrs;
			else
				no_attr = i;
		}
		int hoge, piyo;
		if (attrs == 5)
			hoge = 0, piyo = 5;
		else if (attrs == 4)
			hoge = piyo = no_attr;
		else
		{
			puts("NA");
			continue;
		}

		const int INF = 2 << 24;
		int res = INF;
		int ans_attr = -1;
		for (int okido = hoge; okido <= piyo; ++okido)
		{
			int first = (okido + 1) % 5;
			int last = (okido + 4) % 5;

			for (int i = 0; i < 5; ++i)
				for (int j = 0; j < size[i]; ++j)
					dp[i][j] = INF;
			for (int i = 0; i < size[first]; ++i)
				dp[first][i] = manha(start, node[first][i]);

			for (int i = 0; i < 4; ++i)
			{
				int cur = (first + i) % 5;
				int next = (cur + 1) % 5;
				for (int j = 0; j < size[cur]; ++j)
					for (int k = 0; k < size[next]; ++k)
						dp[next][k] = min(dp[next][k], dp[cur][j] + manha(node[cur][j], node[next][k]));
			}

			int r = INF;
			for (int i = 0; i < size[last]; ++i)
				r = min(r, dp[last][i] + manha(node[last][i], goal));
			if (r < res)
			{
				res = r;
				ans_attr = okido + 1;
			}
		}
		printf("%d %d\n", ans_attr, res);
	}

	return 0;
}