#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;
 
int cost[1002][1<<5];
int pokpos[1002][1002];
char stage[1000][1000];

struct Pos{
	int x;
	int y;
} pos[1002];

class Data{
public:
    int cost;
    int got;
    int x;
    int y;
    Data() : got(0),cost(0),x(0),y(0){}
    Data(int _c,int _g,int _x,int _y) : cost(_c), got(_g),x(_x),y(_y) {}
    bool operator>(const Data& d) const{
        return cost > d.cost;
    }
};
 
int main(){
    int w,h;
    while(~scanf("%d %d",&w,&h)){
        if(w==h && h==0) break;
        int sx,sy;
        int gx,gy;
        int count = 0;
        for(int y=0;y<h;y++){
            char buf[1024];
            scanf("%s",buf);
            for(int x=0;x<w;x++){
                stage[y][x] = buf[x];
                if(buf[x]=='S'){
                    sx = x;
                    sy = y;
                    pokpos[y][x]=count;
					pos[count].x = x;
					pos[count].y = y;
					count++;
                }
 
                else if(buf[x]=='G'){
                    gx = x;
                    gy = y;
                    pokpos[y][x]=count;
					pos[count].x = x;
					pos[count].y = y;
					count++;
                }
                else if(isdigit(buf[x])){
                    pokpos[y][x]=count;
					pos[count].x = x;
					pos[count].y = y;
					count++;
                }
			}
		}
 
 
        int res_pk=-1;
        int res_step = INF;
 
        priority_queue<Data,vector<Data>,greater<Data> > que;
 
        for(int pk=0;pk<=4;pk++){
            que.push(Data(0,1<<pk,sx,sy));
 
            memset(cost,0x3f,sizeof(cost));
            cost[pokpos[sy][sx]][1<<pk] = 0;
 
            while(!que.empty()){
                Data d = que.top();
                que.pop();
                for(int i=0;i<count;i++){
					int dx = pos[i].x;
                    int dy = pos[i].y;
					if(dx == d.x && dy == d.y) continue;

                    int c = abs(dx - d.x) + abs(dy - d.y);
                    int got = d.got;

                    if(isdigit(stage[dy][dx])){
                            int pok = (stage[dy][dx]-'1');
                            pok = (pok == 0 ? 4 : pok - 1);
                            if(got & (1<<pok)) got |= (1<<(stage[dy][dx]-'1'));
                    }
 
                    if(cost[i][got] <= d.cost + c) continue;
 
                    cost[i][got] = d.cost + c;

					if(stage[dy][dx] == 'G' && got == (1<<5)-1) goto next;
                    if(stage[dy][dx] == 'G') continue;

                    que.push(Data(d.cost+c,got,dx,dy));
                }
            }
 next:;
            if(cost[pokpos[gy][gx]][(1<<5)-1] < res_step){
                res_step = cost[pokpos[gy][gx]][(1<<5)-1];
                res_pk = pk;
            }
        }
 
        if(res_pk == -1) printf("NA\n");
        else printf("%d %d\n",res_pk+1,res_step);
    }
}