#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int X,Y;
    for(;;){
        scanf("%d %d\n",&X,&Y);
        if(X==0&&Y==0) break;
        vector<vector<pair<int,int> > > monpos(5,vector<P>());
        int sy,sx,gy,gx;
        for(int i=0;i<Y;i++){
            for(int j=0;j<X;j++){
                char nc;
                scanf("%c",&nc);
                if('1'<=nc&&nc<='5'){
                    monpos[nc-'1'].push_back(make_pair(i,j));
                }else if(nc=='S'){
                    sy=i;
                    sx=j;
                }else if(nc=='G'){
                    gy=i;
                    gx=j;
                }
            }
            scanf("\n");
        }

        int type,md=INT_MAX;

        for(int i=0;i<5;i++){
            int fir=(i+1)%5;
            vector<int> befmind(monpos[fir].size()),nowmind;
            if(monpos[fir].size()==0) continue;
            for(int j=0;j<monpos[fir].size();j++){
                befmind[j]=abs(sy-monpos[fir][j].first)+abs(sx-monpos[fir][j].second);
            }
            int now=fir,bef;
            bool iscont=false;
            for(int ix=0;ix<3;ix++){
                bef=now;
                now=(now+1)%5;
                if(monpos[now].size()==0){
                    iscont=true;
                    break;
                }
                nowmind=vector<int>(monpos[now].size());
                for(int j=0;j<monpos[now].size();j++){
                    nowmind[j]=INT_MAX;
                    for(int k=0;k<monpos[bef].size();k++){
                        nowmind[j]=min(nowmind[j],befmind[k]+abs(monpos[now][j].first-monpos[bef][k].first)+abs(monpos[now][j].second-monpos[bef][k].second));
                    }
                }
                befmind=nowmind;
            }
            if(iscont) continue;
            int lmind=INT_MAX;
            for(int j=0;j<monpos[now].size();j++){
                lmind=min(lmind,nowmind[j]+abs(monpos[now][j].first-gy)+abs(monpos[now][j].second-gx));
            }
            if(lmind<md){
                md=lmind;
                type=i+1;
            }
        }
        if(md==INT_MAX) printf("NA\n");
        else printf("%d %d\n",type,md);
    }
}