#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int dx[] = {-1,0,0,1};
int dy[] = {0,-1,1,0};
int w,h;
int sx,sy,gx,gy;
vector< pair<int,int> > ma[5];
int dp[5][1000];
int num;

int dis(pair<int,int> s1,pair<int,int> s2){
    return abs(s1.first - s2.first) + abs(s1.second - s2.second);
}

int rec(int now,int java){
    if(dp[now][java]) return dp[now][java];
    int ret = 100000,next = (now+1) % 5;
    if(now == num) ret = dis(ma[now][java],pair<int,int>(gy,gx));
    else REP(i,ma[next].size()){
	ret = min (ret,rec(next,i) + dis(ma[now][java],ma[next][i]));
    }
    return dp[now][java] = ret;
}

int main(){

    while(true){
	cin >> w >> h;
	if(w == 0 && h == 0) break;
	memset(dp,0,sizeof(dp));
	REP(i,5) ma[i].clear();
	REP(i,h)REP(j,w){
	    char f;
	    cin >> f;
	    if(f == 'S'){
		sx = j;
		sy = i;
	    }else if(f == 'G'){
		gx = j;
		gy = i;
	    }else if(f != '.') ma[f-'1'].PB(pair<int,int>(i,j));
	}

	pair<int,int> ret = pair<int,int>(100000,100000);
	REP(i,5){
	    REP(j,5)
		REP(k,1000) dp[j][k] = 0;
	    num = (i + 4) % 5;
	    int next = (i + 1) % 5,tmp = 100000;
	    REP(j,ma[next].size()){
		ret = min( ret, pair<int,int>(rec(next,j) + dis(pair<int,int>(sy,sx),ma[next][j]),i+1));
	    }
	}
	if(ret.first == 100000) cout << "NA" << endl;
	else cout << ret.second << " " << ret.first << endl;
    }
    return 0;
}