#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

int w,h;
char field[1024][1024];
int sx,sy,gx,gy;
int dp[7][1024];

class state{
  public:
	int x,y;
	state(int _x, int _y){
		x = _x;  y = _y;
	}
};
vector<state> joutai[7];

int main(){
	while(scanf("%d%d",&w,&h),w|h){
		rep(i,7)rep(j,1024)dp[i][j]=INT_MAX;
		rep(i,7)joutai[i].clear();
		
		rep(i,h){
			scanf("%s",field[i]);
			rep(j,w){
				switch(field[i][j]){
				  case 'S' :
					sx=j; sy=i;
					break;
				  case 'G' :
					gx=j; gy=i;
					break;
				  case '1': case '2': case '3': case '4': case '5':
					joutai[field[i][j]-'0'].push_back(state(j,i));
					break;
				}
			}
		}
		joutai[0].push_back(state(sx,sy));
		joutai[6].push_back(state(gx,gy));

#if DEB
		rep(i,7){
			rep(j,joutai[i].size()){
				printf("(%d,%d), ",joutai[i][j].x, joutai[i][j].y);
			}
			puts("");
		}
#endif


		int ans = INT_MAX;
		int idx;
		dp[0][0] = 0;
		rep(init,5){ //zurasi  5
			int cur,next;
			rep(i,6)rep(j,1024)dp[i][j]=INT_MAX;
			cur = 0;
			dp[0][0] = 0;
			
#if DEB
			printf("-------------init:%d------------\n",init);
#endif			
			rep(i,4){
				next = i+init+1;
				if( next>5 )next -= 5;
#if DEB
				printf("cur:%d  --> next:%d\n",cur,next);
#endif				
				rep(j,joutai[cur].size())if( dp[cur][j]!=INT_MAX ){
					rep(k,joutai[next].size()){
						int dx,dy;
						dx = abs(joutai[cur][j].x - joutai[next][k].x);
						dy = abs(joutai[cur][j].y - joutai[next][k].y);
#if DEB
						printf("(%d,%d) --> (%d,%d)  cost:%d\n",joutai[cur][j].x,
							   joutai[cur][j].y,joutai[next][k].x,joutai[next][k].y,dx+dy);
#endif						
						dp[next][k] = min(dp[next][k], dp[cur][j]+dx+dy);

#if DEB
						printf("dp[%d][%d] : %d\n",next,k,dp[next][k]);
#endif						
					}
				}
				cur = next;
			}

			// cur is last . 6 is goal
#if DEB
			printf("____init:%d  cur:%d   cur.size:%d\n",init,cur,joutai[cur].size());
#endif			
			rep(j,joutai[cur].size())if( dp[cur][j]!=INT_MAX ){
				int dx = abs(joutai[cur][j].x - gx);
				int dy = abs(joutai[cur][j].y - gy);
				if( ans>dp[cur][j]+dx+dy ){
					ans = dp[cur][j] + dx+dy;
					if( init==0 ){
						idx = 5;
					}else{
						idx = init;
					}
				}
			}
		}

		if( ans==INT_MAX ){
			puts("NA");
		}else{
			printf("%d %d\n",idx,ans);
		}
	}
	return 0;
}