#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

char map[1000 + 2][1000 + 2];

int gx, gy;
int size_x, size_y;
int ans;
int ans_el;

using namespace std;

int calc(int x, int y, int get, int have, int dist)
{
	if (have == get){
		if (dist + max(x, gx) - min(x, gx) + max(y, gy) - min(y, gy) < ans){
			ans = dist + max(x, gx) - min(x, gy) + max(y, gy) - min(y, gy);
			ans_el = have;
		}
		return (1);
	}
	if (dist >= ans){
		return (0);
	}
	for (int mx = 1; mx <= size_x; mx++){
		for (int my = 1; my <= size_y; my++){
			if (map[mx][my] - '0' - 1 == get){
				calc(mx, my, (get + 1) % 5, have, dist + max(x, mx) - min(x, mx) + max(y, my) - min(y, my));
			}
		}
	}
	
	return (0);
}
 
int main(void)
{
	int sx, sy;
	int have;
	int get;
	
	while (1){
	
	cin >> size_x >> size_y;
	if (size_x == 0 && size_y == 0)break;
	memset(map, -1, size_x * size_y);
	for (int y = 1; y <= size_y; y++){
		ans = 10000000;
		ans_el = -1;
		char str[1001];
		cin >> str;
		for (int x = 1; x <= size_x; x++){
			if (str[x - 1] == 'S'){
				sx = x;
				sy = y;
			}
			if (str[x - 1] == 'G'){
				gx = x;
				gy = y;
			}
			map[x][y] = str[x - 1];
		}
	}
	
	for (int i = 0; i < 5; i++){
		have = i;
		get = (i + 1) % 5;
		calc(sx, sy, get, have, 0);
	}
	
	if (ans_el == -1){
		cout << "NA" << endl;
	}
	else {
		cout << ans_el + 1 << ' ' << ans << endl;
	}
	}
	return (0);
}