#include <iostream>
#include <vector>
#include <queue>
#include <limits>
#include <cmath>
using namespace std;

struct Vertex {
    int x, y, attr, distance, count;
    void print() {
        cout << "(" << x << "," << y << ") " << attr << " [" << distance << " " << count << "]"  << endl;
    }
};

bool operator<(const Vertex &a, const Vertex &b) {
    return a.distance == b.distance ? a.count > b.count: a.distance > b.distance;
}

const int INF = numeric_limits<int>::max();

int main() {
    int x, y, sx, sy, gx, gy, attr, i, j;
    char t;
    vector<Vertex> vx[6];

    while (cin >> x >> y, x) {
        for (i = 0; i <= 5; i++) {
            vx[i].clear();
        }
        for (i = 0; i < y; i++) {
            for (j = 0; j < x; j++) {
                cin >> t;
                if (t == 'S') {
                    sx = j; sy = i;
                }
                else if (t == 'G') {
                    gx = j; gy = i;
                    Vertex v;
                    v.x = j;
                    v.y = i;
                    v.attr = 0;
                    vx[0].push_back(v);
                }
                else if ('1' <= t && t <= '5') {
                    Vertex v;
                    attr = t - '0';
                    v.x = j;
                    v.y = i;
                    v.attr = attr;
                    vx[attr].push_back(v);
                }
            }
        }

        int min_distance = INF, min_attr;
        for (i = 1; i <= 5; i++) {
            priority_queue<Vertex> q;
            Vertex sv;
            sv.x = sx;
            sv.y = sy;
            sv.attr = i;
            sv.distance = 0;
            sv.count = 1;
            q.push(sv);
            while (!q.empty()) {
                Vertex v = q.top();
                q.pop();
                if (min_distance < v.distance) break;
                if (v.x == gx && v.y == gy) {
                    if (v.distance < min_distance) {
                        min_distance = v.distance;
                        min_attr = i;
                    }
                    break;
                }
                int next_attr;
                if (v.count == 5) {
                    next_attr = 0;
                }
                else {
                    next_attr = (v.attr % 5) + 1;
                }
                for (vector<Vertex>::iterator vitr = vx[next_attr].begin();
                     vitr != vx[next_attr].end(); vitr++) {
                    Vertex nv;
                    nv = *vitr;
                    nv.distance = v.distance +
                                  abs(nv.x - v.x) + abs(nv.y - v.y);
                    nv.count = v.count + 1;
                    q.push(nv);
                }
            }
        }
        if (min_distance == INF) {
            cout << "NA";
        }
        else {
            cout << min_attr << " " << min_distance;
        }
        cout << endl;
    }
    return 0;
}