#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

#define f first
#define s second


typedef pair<int,int> pii;
const int W = 1111;
const int INF = 1000000000;

int w,h;
char board[W][W];


bool input(){
	cin>>w>>h;
	
	if(w==0)return false;
	rep(i,h){
		string str;
		cin>>str;
		rep(j,w){
			board[i][j] = str[j];
		}
	}
	return true;
}

class P{
	public:
	int x,y,num,val;
	P(int x,int y,int num,int val):x(x),y(y),num(num),val(val){}
};


void plusBoard(){
	rep(i,h){
		rep(j,w){
			char c = board[i][j];
			if('1'<=c && c<='5')board[i][j] = ((c+4)-'1')%5 + '1';
		}
	}
}

const int T = 6;
bool visit[W][W][T];
bool isnum(char c){
	return '0'<=c && c<='9';
}
int haba(){
	queue<P> que;
	rep(i,h)rep(j,w)if(board[i][j]=='S')que.push(P(j,i,1,0));
	rep(i,w)rep(j,h)rep(k,T)visit[i][j][k]=0;
	
	while(1){
		if(que.empty())break;
		
		P u = que.front(); que.pop();
		
		if(visit[u.y][u.x][u.num]==1)continue;
		visit[u.y][u.x][u.num]=1;
		
		//printf("%d %d %d %d\n",u.y,u.x,u.num,u.val);
		
		if(isnum(board[u.y][u.x])){
			if(u.num+1<board[u.y][u.x]-'0')continue;
			u.num = max(u.num,  board[u.y][u.x]-'0');
		}
		
		
		if(board[u.y][u.x]=='G' && u.num==5){
			return u.val;
		}
		
		
		int dx[]={1,0,-1,0};
		int dy[]={0,1,0,-1};
		
		rep(i,4){
			int nx = u.x+dx[i];
			int ny = u.y+dy[i];
			if(isnum(board[ny][nx]) && u.num+1<board[ny][nx]-'0')continue;
			if(nx<0 || ny<0 || nx>=w || ny>=h)continue;
			que.push(P(nx, ny, u.num, u.val+1));
		}
	}
	return INF;
}


pii solve(){
	
	vector<pii> rec;
	rep(i,5){
		int a = haba();
		plusBoard();
		rec.push_back(pii(i+1,a));
	}
	
	rep(i,rec.size()){
		rep(j,rec.size()){
			if(rec[i].s < rec[j].s)swap(rec[i], rec[j]);
		}
	}
	
	/*
	rep(i,rec.size()){
		printf("ans = %d %d\n",rec[i].f, rec[i].s);
	}*/
	
	if(rec[0].s == INF)return pii(-1,-1);
	return rec[0];
}

void csolve(){
	pii val = solve();
	
	if(val.f==-1)puts("NA");
	else printf("%d %d\n",val.f, val.s);
}


int main(){
	while(input())csolve();
}