#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int dy[] = {0, 0, -1, 1};
    int dx[] = {1, -1, 0, 0};

    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        vector<string> grid(h);
        int sy, sx, gy, gx;
        for(int i=0; i<h; ++i){
            cin >> grid[i];
            int j = grid[i].find('S');
            if(j != string::npos){
                sy = i;
                sx = j;
                grid[i][j] = '.';
            }
            j = grid[i].find('G');
            if(j != string::npos){
                gy = i;
                gx = j;
                grid[i][j] = '.';
            }
        }

        pair<int, int> ret(INT_MAX, INT_MAX);

        for(int k=0; k<5; ++k){
            queue<pair<pair<int, int>, int> > q;
            q.push(make_pair(make_pair(sy, sx), 1<<k));
            vector<vector<vector<int> > > minCost(h, vector<vector<int> >(w, vector<int>(32, INT_MAX)));
            minCost[sy][sx][1<<k] = 0;

            while(!q.empty()){
                int y0 = q.front().first.first;
                int x0 = q.front().first.second;
                int pachi0 = q.front().second;
                int cost = minCost[y0][x0][pachi0];
                q.pop();

                if(y0 == gy && x0 == gx && pachi0 == 31){
                    ret = min(ret, make_pair(cost, k));
                    break;
                }

                for(int i=0; i<4; ++i){
                    int y = y0 + dy[i];
                    int x = x0 + dx[i];
                    if(y < 0 || y >= h || x < 0 || x >= w)
                        continue;
                    int pachi = pachi0;
                    if(grid[y][x] != '.'){
                        int j = grid[y][x] - '1';
                        if(pachi & (1<<((j+4)%5)))
                            pachi |= (1<<j);
                    }

                    if(cost + 1 < minCost[y][x][pachi]){
                        minCost[y][x][pachi] = cost + 1;
                        q.push(make_pair(make_pair(y, x), pachi));
                    }
                }
            }
        }

        if(ret.first == INT_MAX)
            cout << "NA" << endl;
        else
            cout << (ret.second + 1) << ' ' << ret.first << endl;
    }
}