#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()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        int sy, sx, gy, gx;
        vector<vector<int> > py(5), px(5);

        for(int i=0; i<h; ++i){
            string s;
            cin >> s;
            for(int j=0; j<w; ++j){
                if(s[j] == 'S'){
                    sy = i;
                    sx = j;
                }else if(s[j] == 'G'){
                    gy = i;
                    gx = j;
                }else if(s[j] != '.'){
                    py[s[j]-'1'].push_back(i);
                    px[s[j]-'1'].push_back(j);
                }
            }
        }

        pair<int, int> ret(INT_MAX, INT_MAX);
        for(int i=0; i<5; ++i){
            int a = (i+1) % 5;
            int b = (i+2) % 5;

            int n = py[a].size();
            vector<int> cost(n);
            for(int j=0; j<n; ++j)
                cost[j] = abs(sy - py[a][j]) + abs(sx - px[a][j]);

            for(int j=0; j<3; ++j){
                int m = py[b].size();
                vector<int> nextCost(m, INT_MAX);
                for(int k=0; k<n; ++k){
                    for(int l=0; l<m; ++l){
                        nextCost[l] = min(nextCost[l], cost[k] + abs(py[a][k] - py[b][l]) + abs(px[a][k] - px[b][l]));
                    }
                }
                n = m;
                cost.swap(nextCost);
                (++a) %= 5;
                (++b) %= 5;
            }

            for(int j=0; j<n; ++j)
                ret = min(ret, make_pair(cost[j] + abs(gy - py[a][j]) + abs(gx - px[a][j]), i+1));
        }

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