#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;
};

const int INF=100000000;
int main(){

	int w,h;

	// »ê¼êÌíÞÌm[hði[
	while(cin>>w>>h&&!(w==0&&h==0)){
		// dpe[u
		int dp[5][1001];
		// m[hÌÊu
		vector<edge> G[6][1001];
		char field[1001][1001];
		vector<pair<int,int> > p[6];
		pair<int,int> goal;
		pair<int,int> start;
		int minCost=INF;
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 1001; j++){
				dp[i][j]=INF;
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				if(field[i][j]=='S'){
					start.first=i;
					start.second=j;
				}
				else if(field[i][j]=='G'){
					goal.first=i;
					goal.second=j;
				}
				else if(field[i][j]!='.'){
					int num=field[i][j]-'0'-1;
					p[num].push_back(make_pair(i,j));
				}
			}
		}

		// iªX^[gn_
		int bestIdx=-1;
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 5; j++){
				fill(dp[j],dp[j]+1001,INF);
			}
			for(int j = 0; j < p[(i+1)%5].size(); j++){
				// X^[g©çÌ£
				dp[(i+1)%5][j]=abs(start.first-p[(i+1)%5][j].first) + abs(start.second-p[(i+1)%5][j].second);
			}
			// jª¡Ìm[h
			for(int j = i+1; j < i+4; j++){
				// Ü¸æÌm[hðßA»±ÉÎµÄÚ®ðs¤B
				for(int l = 0; l < p[(j+1)%5].size(); l++){
					for(int k = 0; k < p[j%5].size(); k++){
						dp[(j+1)%5][l]=min(dp[(j+1)%5][l]
						,dp[j%5][k]+abs(p[j%5][k].first-p[(j+1)%5][l].first)+abs(p[j%5][k].second-p[(j+1)%5][l].second));
					}
				}
			}
			// ÅãÉS[ÜÅÌRXgªÅZÈàÌðßé
			for(int j = 0; j < p[(i+4)%5].size(); j++){
				if(minCost>dp[(i+4)%5][j]+abs(goal.first-p[(i+4)%5][j].first)+abs(goal.second-p[(i+4)%5][j].second)){
					minCost=dp[(i+4)%5][j]+abs(goal.first-p[(i+4)%5][j].first)+abs(goal.second-p[(i+4)%5][j].second);
					bestIdx=i+1;
				}
			}
		}
		if(bestIdx!=-1)
			cout<<bestIdx<<" "<<minCost<<endl;
		else
			cout<<"NA"<<endl;
	}
	return 0;
}