#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>
#include <cstring>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int kind;
	int number;
	int cost;
};

// ツノツーツドツづ個暗環置
vector<edge> G[6][1001][32];
int d[6][1001][32];
const int INF = 1000000000;


class Situation{
public:
	Situation(int _cost,int _kind,int _number,int _used){
		cost = _cost;
		kind=_kind;
		used = _used;
		number=_number;
	}

	Situation();

	int cost;
	int kind;
	int number;
	int used;

	bool operator<(const Situation &sit)const{
		return sit.cost < (this->cost);
	}
};

void dijkstra(int init){
	priority_queue<Situation> que;

	for(int i = 0; i < 6; i++)
		for(int j = 0; j < 1001; j++)
			for(int k = 0; k < 32; k++)
				d[i][j][k]=INF;
	d[init][0][1<<init]=0;
	
	que.push(Situation(0,init,0,1<<init));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
		int k = p.kind;
		int used=p.used;
		int number=p.number;

		if(d[k][number][used]<p.cost){
			continue;
		}
		for(int i = 0; i < G[k][number][used].size(); i++){
			edge e = G[k][number][used][i];
			if(d[k][number][used]+e.cost<d[e.kind][e.number][used|(1<<e.kind)]){
				d[e.kind][e.number][used|(1<<e.kind)]=d[k][number][used]+e.cost;
				que.push(Situation(d[e.kind][e.number][used|(1<<e.kind)],e.kind,e.number,used|(1<<e.kind)));
			}
		}
	}
}

struct info{
	int x,y;
	char kind;
};



int main(){

	int w,h;
	while(cin>>w>>h&&!(w==0&&h==0)){
		int ct[6];
		char field[1001][1001];
		int cs[1001][1001];
		pair<int,int> ctt[6][1001];
		memset(cs,0,sizeof(cs));

		for(int i = 0; i < 6; i++)
			ct[i]=0;

		
		vector<info> place;
		pair<int,int> goal;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				if(field[i][j]!='.'&&field[i][j]!='G'&&field[i][j]!='S'){
					info inf;
					inf.x=j;
					inf.y=i;
					inf.kind=field[i][j];
					place.push_back(inf);
					ct[inf.kind-'0'-1]++;
					cs[inf.y][inf.x]=ct[inf.kind-'0'-1];
					ctt[inf.kind-'0'-1][ct[inf.kind-'0'-1]].first=i;
					ctt[inf.kind-'0'-1][ct[inf.kind-'0'-1]].second=j;
				}
				else if(field[i][j]=='G'){
					goal.first=i;
					goal.second=j;
				}
				else if(field[i][j]=='S'){
					info inf;
					inf.x=j;
					inf.y=i;
					inf.kind='S';
					place.push_back(inf);
					cs[inf.y][inf.x]=0;
				}
			}
		}

		bool passed[1001][1001][6];
		memset(passed,0,sizeof(passed));
		for(int i = 0; i < place.size(); i++){
			for(int j = 0; j < place.size(); j++){
				if(i!=j){
					int dist=abs(place[i].y-place[j].y)+abs(place[i].x-place[j].x);
					if(place[i].kind=='S'){
						// ツづづェツづーツづ^[g·é©
						for(int k = 0; k < 5; k++){
							edge in;
							in.kind=place[j].kind-'0'-1;
							in.cost=dist;
							in.number=cs[place[j].y][place[j].x];
							if((place[j].kind-'0'-1)==(k+1)%5)
								G[k][0][1<<k].push_back(in);
						}
					}
					else{
						if(place[j].kind=='S')
							continue;

						if(place[i].kind=='2'&&place[j].kind=='3'){
						}
						// ÇÌóÔÅü©¤©
						for(int k = 0; k < 32; k++){
							edge e;
							e.number=cs[place[j].y][place[j].x];
							e.cost=dist;
							e.kind=place[j].kind-'0'-1;
							int toKind=e.kind;
							if(!((k>>toKind)&1)&&((place[i].kind-'0'-1)+1)%5==toKind){
								G[place[i].kind-'0'-1][cs[place[i].y][place[i].x]][k].push_back(e);
							}
						}
					}
				}
			}
		}
		int minCost=INF;
		int idx;
		// startn_ð¢­Â©·
		for(int i = 0; i < 5; i++){
			dijkstra(i);
			for(int j = 0; j < 1001; j++){
				for(int k = 0; k < 5; k++){
					pair<int,int> p = ctt[k][j];
					int dist=abs(p.first-goal.first)+abs(p.second-goal.second);
					if(minCost>d[k][j][31]+dist){
						minCost=min(minCost,d[k][j][31]+dist);
						idx=i;
					}
				}
			}

		}
		if(minCost==INF)
			cout<<"NA"<<endl;
		else{
			cout<<idx+1<<" "<<minCost<<endl;
		}
		for(int i = 0; i < 6; i++)
			for(int j = 0; j < 1001;j++)
				for(int k = 0; k < 32; k++)
					G[i][j][k].clear();
	}

	return 0;
}