#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	void init(){
		cost = BIG_NUM;
	}
	int row,col,cost;
};

int main(){

	int W,H,first,minimum = BIG_NUM,minimum_first,next,current;
	Info start,goal;
	vector<Info> V[6];
	char buf[1001];

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		for(int i = 1; i <= 5; i++)V[i].clear();

		for(int i = 0; i < H; i++){
			scanf("%s",buf);
			for(int k = 0; buf[k] != '\0'; k++){
				if(buf[k] == '.'){
					//Do nothing
				}else{
					if(buf[k] == 'S'){
						start.row = i;
						start.col = k;
					}else if(buf[k] == 'G'){
						goal.row = i;
						goal.col = k;
					}else{
						Info info;
						info.row = i;
						info.col = k;
						V[buf[k] - '0'].push_back(info);
					}
				}
			}
		}

		minimum = BIG_NUM;

		for(first = 1; first <= 5; first++){
			for(int i = 1; i <= 5; i++){
				for(int k = 0; k < V[i].size();k++)V[i][k].init();
			}
			goal.cost = BIG_NUM;

			if(first == 5){
				next = 1;
			}else{
				next = first+1;
			}

			for(int i = 0; i < V[next].size(); i++){
				V[next][i].cost = abs(start.row-V[next][i].row)+abs(start.col-V[next][i].col);
			}

			current = next;

			for(int i = 1; i <= 3; i++){
				next++;
				if(next == 6)next = 1;

				for(int a = 0; a < V[current].size(); a++){
					for(int b = 0; b < V[next].size();b++){
						V[next][b].cost = min(V[next][b].cost,V[current][a].cost+abs(V[next][b].row-V[current][a].row)+abs(V[next][b].col-V[current][a].col));
					}
				}
				current = next;
			}

			for(int i = 0; i < V[current].size();i++){
				goal.cost = min(goal.cost,V[current][i].cost+abs(goal.row-V[current][i].row)+abs(goal.col-V[current][i].col));
			}

			if(goal.cost < minimum){
				minimum = goal.cost;
				minimum_first = first;
			}
		}

		if(minimum == BIG_NUM){
			printf("NA\n");
		}else{
			printf("%d %d\n",minimum_first,minimum);
		}
	}

	return 0;
}