#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <complex>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#define INF 1<<30
#define EPS 1e-15
const int dx[] = {1,0,-1,0,1,-1,-1,1};
const int dy[] = {0,1,0,-1,1,1,-1,-1};
#define PB push_back
#define fi first
#define se second
#define rep(i,j) for(int  i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector < int > vi;
typedef vector < vi > vvi;
class data{
	public:
	int y;
	int x;
	int vis;
	int cnt;
	int base;
	data(){}
	data(int _y,int _x,int _vis,int _cnt,int _base){
		y = _y;
		x = _x;
		vis = _vis;
		cnt = _cnt;
		base = _base;
	}
	bool operator<(const data &a)const{
		int n1=0,n2=0;
		reps(i,1,6){
			if(vis>>i & 1)n1++;
			if(a.vis>>i & 1)n2++;
		}
		if(n1 == n2 && cnt == a.cnt)return base>a.base;
		if(n1 == n2)return cnt>a.cnt;
		return n1>n2;	
	}
};
char stage[1024][1024];
bool memo[1024][1024][1<<5];
int main(){
	int w,h;
	while(scanf("%d%d",&w,&h),(w|h)){
		memset(stage,0,sizeof(stage));
		memset(memo,0,sizeof(memo));
		int sy,sx;
		int gy,gx;
		rep(i,h){
			scanf("%s",stage[i]);
			rep(j,w){
				if(stage[i][j] == 'S'){
					sy = i;
					sx = j;
				}
				if(stage[i][j] == 'G'){
					gy = i;
					gx = j;
				}
			}
		}
		priority_queue < data > Q;
		rep(i,5){
			Q.push(data(sy,sx,1<<i,0,(i+1)%5+1));
			memo[sy][sx][1<<i]=true;
		}

		int ans[2] = {INF,INF};
		while(!Q.empty()){
			data d = Q.top();Q.pop();
			if(d.y == gy && d.x == gx && (1<<5)-1 == d.vis){
				ans[0] = d.base;
				ans[1] = d.cnt;
				break;
			}
			rep(i,4){
				int ny = d.y+dy[i];
				int nx = d.x+dx[i];
				if(ny < 0 || ny > h-1 || nx < 0 || nx > w-1)continue;
				if(stage[ny][nx]!='.' && isdigit(stage[ny][nx]) && d.base == stage[ny][nx]-'0'){
					if(memo[ny][nx][d.vis|(1<<(stage[ny][nx]-'0'-1))]++)continue;
					Q.push(data(ny,nx,d.vis|(1<<stage[ny][nx]-'0'-1),d.cnt+1,d.base%5+1));		
				}
				if(memo[ny][nx][d.vis]++)continue;
				Q.push(data(ny,nx,d.vis,d.cnt+1,d.base));
			}
		}
		if(ans[0] == INF)puts("NA");
		else printf("%d %d\n",ans[0],ans[1]);
	}	
	return 0;
}