#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;
vector < Pii > D[7];
vector < Pii > N[7];
int main(){
	int W,H;
	while(scanf("%d%d",&W,&H),(W|H)){
		rep(i,7){
			D[i].clear();
		}
		rep(i,H){
			char s[1024];
			scanf("%s",s);
			rep(j,W){
				if(s[j] == 'S'){
					D[0].PB(Pii(i,j));
				}
				else if(s[j] == 'G'){
					D[6].PB(Pii(i,j));
				}
				else if(s[j] != '.'){
					D[s[j]-'0'].PB(Pii(i,j));
				}
			}
		}
		int dp[6][1024];
		Pii ans;
		ans.fr = INF;
		ans.sc = INF;

		N[0] = D[0];
		N[5] = D[6];
		
		reps(f,1,6){
			//init
			rep(i,6){
				rep(j,1024){
					dp[i][j] = INF;
				}
			}
			dp[0][0] = 0;

			//p
			reps(i,1,5){
				int prev = ((f+i-1)%5)+1;
				N[i] = D[prev];
			}

			//dp
			rep(i,6){
				if(i == 5)continue;
				rep(j,N[i].size()){
					rep(k,N[i+1].size()){
						dp[i+1][k] = min(dp[i+1][k],dp[i][j]+abs(N[i][j].fr-N[i+1][k].fr)+abs(N[i][j].sc-N[i+1][k].sc));
						//printf("%d\n",dp[i+1][k]);
					}
				}
			}

			//update
			ans = min(ans,Pii(dp[5][0],f));
		}

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