#include<bits/stdc++.h>
using namespace std;
struct data{
    int y,x,S,cost;
    data(int y,int x,int cost,int S):
        y(y),x(x),cost(cost),S(S){}
    data(){}
    bool operator<(const data &d)const{
        return cost>d.cost;
    }
};
int sy,sx,gy,gx;
int H,W;
int fld[1000][1000];
bool dist[1000][1000][1<<5];
const int INF=1<<30;
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int solve(int se){
    fill_n(**dist,1000*1000*(1<<5),false);
    dist[sy][sx][1<<se]=true;
    priority_queue<data>Q;
    Q.push(data(sy,sx,0,1<<se));

    while(!Q.empty()){
        data d=Q.top();Q.pop();
        if(d.y==gy&&d.x==gx&&d.S==(1<<5)-1){
            return d.cost;
        }

        for(int i=0;i<4;i++){
            int ty=d.y+dy[i],tx=d.x+dx[i];
            if(ty<0||ty>=H||tx<0||tx>=W)continue;
            int tS;
            if(fld[ty][tx]!=-1&&((d.S>>((fld[ty][tx]+5-1)%5))&1)){
                tS=d.S|(1<<fld[ty][tx]);
            }
            else tS=d.S;
            if(dist[ty][tx][tS])continue;
            dist[ty][tx][tS]=true;
            Q.push(data(ty,tx,d.cost+1,tS));
        }
    }
}
int main(){
    while(cin>>W>>H,W||H){
        int crrect=0;
        for(int i=0;i<H;i++){
            char str[1000];
            cin>>str;
            for(int j=0;j<W;j++){
                if(str[j]=='S'){
                    sy=i;
                    sx=j;
                }
                else if(str[j]=='G'){
                    gy=i;
                    gx=j;
                }
                if(isdigit(str[j])){
                    int num=str[j]-'0'-1;
                    fld[i][j]=num;
                    crrect|=(1<<num);
                }
                else fld[i][j]=-1;
            }
        }
        int minCost=INT_MAX/4,minNode=-1;
        for(int i=0;i<5;i++){
            if((crrect|(1<<i))+1!=(1<<5))continue;
            int val=solve(i);
            if(minCost>val){
                minCost=val;
                minNode=i;
            }
        }
        if(minNode==-1)cout<<"NA"<<endl;
        else cout<<minNode+1<<" "<<minCost<<endl;
    }
    return 0;
}