#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{
        if(cnt == a.cnt)return base>a.base;
        return cnt>a.cnt;
    }
};
char stage[1024][1024];
bool memo[1024][1024][1<<5];
int main(){
    int w,h;
    while(scanf("%d%d",&w,&h),(w|h)){
        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;
                }
            }
        }
		int tmp;
        priority_queue < data > Q;
        rep(i,5){
			tmp = i+1;
			if(tmp == 5)tmp = 0;
            Q.push(data(sy,sx,1<<i,0,tmp+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' && !(d.vis>>(d.base-1) & 1)){
                    if(memo[ny][nx][d.vis|(1<<(d.base-1))]++)continue;
					tmp = d.base;
					if(tmp == 5)tmp = 0;
                    Q.push(data(ny,nx,d.vis|(1<<(d.base-1)),d.cnt+1,tmp+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;
}