#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <string,int> P;
typedef pair <int,int> Pn;
typedef pair <int,P> PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int cost[1000000][1<<5];
char stage[1000][1000];

class Data{
public:
	int cost;
	int got;
	int x;
	int y;
	Data() : got(0),cost(0),x(0),y(0){}
	Data(int _c,int _g,int _x,int _y) : cost(_c), got(_g),x(_x),y(_y) {}
	bool operator>(const Data& d) const{
		return cost > d.cost;
	}
};

int main(){
	int w,h;
	while(~scanf("%d %d",&w,&h)){
		if(w==h && h==0) break;
		int sx,sy;
		int gx,gy;
		for(int y=0;y<h;y++){
			char buf[1024];
			scanf("%s",buf);
			for(int x=0;x<w;x++){
				stage[y][x] = buf[x];
				if(buf[x]=='S'){
					sx = x;
					sy = y;
				}

				else if(buf[x]=='G'){
					gx = x;
					gy = y;
				}
			}
		}


		int res_pk=-1;
		int res_step = INF;

		priority_queue<Data,vector<Data>,greater<Data> > que;

		for(int pk=0;pk<=4;pk++){
			que.push(Data(0,1<<pk,sx,sy));

			memset(cost,0x3f,sizeof(cost));
			cost[sy*w+sx][1<<pk] = 0;

			while(!que.empty()){
				Data d = que.top();
				que.pop();
				for(int i=0;i<4;i++){
					int dx = d.x + tx[i];
					int dy = d.y + ty[i];
					if(dx < 0 || dx >= w || dy < 0 || dy >= h) continue;

					int got = d.got;
					if(stage[dy][dx] != '.' 
						&& stage[dy][dx] != 'S' 
						&& stage[dy][dx] != 'G'){
						got |= (1<<(stage[dy][dx]-'1'));
					}

					if(cost[dy*w+dx][got] <= d.cost + 1) continue;

					cost[dy*w+dx][got] = d.cost+1;

					if(stage[dy][dx] == 'G') continue;
					que.push(Data(d.cost+1,got,dx,dy));
				}
			}

			if(cost[gy*w+gx][(1<<5)-1] < res_step){
				res_step = cost[gy*w+gx][(1<<5)-1];
				res_pk = pk;
			}
		}

		if(res_pk == -1) printf("NA\n");
		else printf("%d %d\n",res_pk+1,res_step);
	}
}