#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;


int enc(int attr, int no)
{
	return no*10 + attr;
}
void dec(int e, int& attr, int& no)
{
	attr = e % 10;
	no = e / 10;
}
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)
	{
		vector<pint> node[7];
		for (int y = 0; y < h; ++y)
		{
			char buf[128];
			scanf("%s", buf);
			for (int x = 0; x < w; ++x)
			{
				if (buf[x] == 'S')
					node[0].push_back(pint(x, y));
				else if (buf[x] == 'G')
					node[6].push_back(pint(x, y));
				else if (isdigit(buf[x]))
					node[buf[x] - '0'].push_back(pint(x, y));
			}
		}

		map<int, vector<pint> > edge;
		for (int i = 1; i <= 5; ++i)
			for (int j = 0; j < node[i].size(); ++j)
				for (int k = 0; k < node[i%5 + 1].size(); ++k)
					edge[enc(i, j)].push_back(pint(manha(node[i][j], node[i%5 + 1][k]), enc(i%5 + 1, k)));


		int attrs = 0;
		int no_attr;
		for (int i = 1; i <= 5; ++i)
		{
			if (node[i].size())
				++attrs;
			else
				no_attr = i;
		}
		int hoge, piyo;
		if (attrs == 5)
		{
			hoge = 1;
			piyo = 5;
		}
		else if (attrs == 4)
			hoge = piyo = no_attr;
		else
		{
			puts("NA");
			continue;
		}
			
		int ans_attr;
		int res = 1000000000;
		for (int init_attr = hoge; init_attr <= piyo; ++init_attr)
		{
			map<int, int> dis;
			priority_queue<pint, vector<pint>, greater<pint> > q;
			for (int i = 0; i < node[init_attr%5 + 1].size(); ++i)
			{
				int next = enc(init_attr%5 + 1, i);
				int cost = manha(node[0][0], node[init_attr%5 + 1][i]);
				dis[next] = cost;
				q.push(pint(cost, next));
			}
			while (!q.empty())
			{
				pint t = q.top(); q.pop();
				int attr, no, cost;
				cost = t.first;
				if (cost > dis[t.second])
					continue;

				dec(t.second, attr, no);

				if (attr == 6)
				{
					if (cost < res)
					{
						ans_attr = init_attr;
						res = cost;
					}
					break;
				}
				else if (attr == (init_attr-1 + 4)%5 + 1)
				{
					int next_cost = cost + manha(node[attr][no], node[6][0]);
					const int goal = enc(6, 0);
					if (!dis.count(goal) || next_cost < dis[goal])
					{
						dis[goal] = next_cost;
						q.push(pint(next_cost, goal));
					}
				}
				else
				{
					for (int i = 0; i < edge[t.second].size(); ++i)
					{
						int next_cost = cost + edge[t.second][i].first;
						int to = edge[t.second][i].second;
						if (!dis.count(to) || next_cost < dis[to])
						{
							dis[to] = next_cost;
							q.push(pint(next_cost, to));
						}
					}
				}
			}
		}
		printf("%d %d\n", ans_attr, res);

	}

	return 0;
}