#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int stage[1024][1024];
struct data
{
	int y;
	int x;
	int type;
	data(){}
	data(int _y,int _x,int _type){
		y = _y;
		x = _x;
		type = _type;
	}
};
struct node
{
	int to;
	int cost;
	int type;
	node(){}
	node(int _to,int _cost,int _type){
		to = _to;
		cost = _cost;
		type = _type;
	}
};
struct q
{
	int to;
	int cost;
	int state;
	int f;
	q(){}
	q(int _to,int _cost,int _state,int _f){
		to = _to;
		cost = _cost;
		state = _state;
		f = _f;
	}
	bool operator<(const q &a)const{
		if(cost == a.cost)return f>a.f;
		return cost>a.cost;
	}
};
int d[10240][64];
vector < node > Graph[10240];
int main(){
	int W,H;
	while(scanf("%d%d",&W,&H),(W|H)){
		memset(stage,0,sizeof(stage));
		rep(i,10240){
			Graph[i].clear();
		}
		Pii start,goal;
		int sIndex,gIndex;
		vector < data > D;
		rep(i,H){
			char s[1024];
			scanf("%s",s);
			rep(j,W){
				if(s[j] == 'S'){
					start.fr = i;
					start.sc = j;
					sIndex = D.size();
					D.PB(data(i,j,0));
				}
				else if(s[j] == 'G'){
					goal.fr = i;
					start.sc = j;
					gIndex = D.size();
					D.PB(data(i,j,0));
				}
				else if(s[j] != '.'){
					D.PB(data(i,j,s[j]-'0'));
				}
			}
		}
		rep(i,D.size()){
			reps(j,i+1,D.size()){
				Graph[i].PB(node(j,abs(D[i].y-D[j].y)+abs(D[i].x-D[j].x),D[j].type));
				Graph[j].PB(node(i,abs(D[i].y-D[j].y)+abs(D[i].x-D[j].x),D[i].type));		
			}
		}
		priority_queue < q > Q;
		reps(i,1,6){
			Q.push(q(sIndex,0,(1<<i)+1,i));
		}
		Pii ans;
		ans.fr = -1;
		ans.sc = -1;
		rep(i,10240){
			rep(j,1<<6){
				d[i][j] = INF;
			}
		}
		while(!Q.empty()){
			q e = Q.top();Q.pop();
			if(e.to == gIndex && e.state == (1<<6) -1){
				ans.fr = e.f;
				ans.sc = e.cost;
				break;
			}
			//printf("%d %d %d\n",e.to,e.state,e.cost);
			d[e.to][e.state] = e.cost;
			int bit = e.state;
			rep(i,Graph[e.to].size()){
				int target = Graph[e.to][i].type-1;
				if(target == 0)target = 5;
				if(target == -1){
					if(d[Graph[e.to][i].to][bit] != INF)continue;
					Q.push(q(Graph[e.to][i].to,e.cost+Graph[e.to][i].cost,bit,e.f));	
				}
				else if(1&(bit>>target)){
					if(d[Graph[e.to][i].to][bit|1<<Graph[e.to][i].type] != INF)continue;
					Q.push(q(Graph[e.to][i].to,e.cost+Graph[e.to][i].cost,bit|1<<Graph[e.to][i].type,e.f));
				}

			}
		}
		if(ans.fr == -1){
			puts("NA");
		}
		else{
			printf("%d %d\n",ans.fr,ans.sc);
		}
	}
	return 0;
}