#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>

using namespace std;

int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

struct Data
{
	int x, y, dist, state;
	Data() {}
	Data(int _x, int _y, int _dist, int _state)
	{
		x = _x;
		y = _y;
		dist = _dist;
		state = _state;
	}
};

char fld[1000][1000];
bool isUsed[5][1000][1000];

inline int GetNext(int n)
{
	return (n == 4) ? 0 : n + 1;
}

inline int GetPrev(int n)
{
	return (n == 0) ? 4 : n - 1;
}

signed main()
{
	int W, H;
	while (cin >> W >> H, W || H)
	{
		int sx, sy, gx, gy;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				scanf(" %c", &fld[i][j]);
				if (fld[i][j] == 'S')
				{
					sx = j;
					sy = i;
				}
				else if (fld[i][j] == 'G')
				{
					gx = j;
					gy = i;
				}
			}
		}
		
		int mi = INT_MAX / 2, ans;
		for (int i = 0; i < 5; i++)
		{
			queue<Data> q;
			Data qf;
			q.push(Data(sx, sy, 0, i));
			fill_n((bool*)isUsed, 5 * 1000 * 1000, false);
			isUsed[i][sy][sx] = true;
			while (!q.empty())
			{
				qf = q.front();
				q.pop();
				if (qf.x == gx && qf.y == gy && qf.state == GetPrev(qf.state))
				{
					if (mi > qf.dist)
					{
						mi = qf.dist;
						ans = i;
						break;
					}
				}
				for (int j = 0; j < 4; j++)
				{
					int nx = qf.x + dx[j];
					int ny = qf.y + dy[j];
					if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
					int state = qf.state;
					if (isUsed[state][ny][nx]) continue;
					isUsed[state][ny][nx] = true;
					if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state))
					{
						state = GetNext(state);
					}
					q.push(Data(nx, ny, qf.dist + 1, state));
				}
			}
		}
		if (mi == INT_MAX / 2) puts("NA");
		else printf("%d %d\n", ans, mi);
	}
	return 0;
}