import std.stdio;
import std.functional;
import std.math;
import std.algorithm;
import std.string;
import std.typecons;

alias Tuple!(int, "y", int , "x") P;

void main() {
    int X, Y; 
    string[] F;
    static char next(char c) {
        if (c == '5') return '1';
        else return cast(char)(c + 1);
    }
    static char prev(char c) {
        if (c == '1') return '5';
        else return cast(char)(c - 1);
    }
    static int dist(P s, P t) {
        return abs(s.y - t.y) + abs(s.x - t.x);
    }
    P s, g;
    P[][char] cs;
    void init() {
        cs = (P[][char]).init;
        foreach (i; 0 .. Y) {
            foreach (j; 0 .. X) {
                if ('1' <= F[i][j] && F[i][j] <= '5') {
                    cs[F[i][j]] ~= P(i, j);
                }
                if (F[i][j] == 'S') {
                    s.y = i;
                    s.x = j;
                } 
                if (F[i][j] == 'G') {
                    g.y = i;
                    g.x = j;
                }
            }
        }
    }
    struct Cache {
        P pos;
        char cur, last;
        bool opEquals(Cache o) {
            return pos == o.pos && cur == o.cur && last == o.last;
        }
    }
    int cache[Cache];
    int dfs(P pos, char cur, char last) {
        if (cur == last) {
            return dist(pos, g);
        }
        auto q = Cache(pos, cur, last);
        if (cache.get(q, false)) return cache[q];
        char n = next(cur);
        int ans = int.max / 2;
        foreach (nnode; cs.get(n, [])) {
            ans = min(ans, dist(pos, nnode) + dfs(nnode, n, last));
        }
        return cache[q] = ans;
    }
    while (readf("%d %d\n", &X, &Y), X || Y) {
        F = new string[Y];
        foreach (ref L; F) L = readln.chomp;
        init;
        int ans = int.max / 2;
        char first = '0';
        for (char k = '1'; k <= '5'; k++) {
            int cand = dfs(s, k, prev(k));
            if (ans > cand) {
                ans = cand;
                first = k;
            }
        }
        if (first == '0') {
            "NA".writeln;
        } else {
            writeln(first, " ", ans);
        }
    }
}