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;
int dist(P s, P t) {
    return abs(s.y - t.y) + abs(s.x - t.x);
}
int next(int c) {
    return (c + 1) % 5;
}
int prev(int c) {
    return (c + 5 - 1) % 5;
}

void main() {
    int X, Y; 
    string[] F;
    P s, g;
    P[][] cs;
    void init() {
        cs = new P[][5];
        foreach (i; 0 .. Y) {
            foreach (j; 0 .. X) {
                char c = F[i][j];
                if ('1' <= c && c <= '5') {
                    cs[c - '1'] ~= P(i, j);
                }
                if (c == 'S') {
                    s.y = i;
                    s.x = j;
                } 
                if (c == 'G') {
                    g.y = i;
                    g.x = j;
                }
            }
        }
    }
    int _dfs(P pos, int cur, int last) {
        alias memoize!_dfs dfs;
        if (cur == last) {
            return dist(pos, g);
        }
        int n = next(cur);
        int ans = int.max / 2;
        cs[n].sort!(delegate(a, b) {
            return pos.dist(a) < pos.dist(b);
        });
        foreach (nnode; cs[n]) {
            ans = min(ans, dist(pos, nnode) + dfs(nnode, n, last));
        }
        return ans;
    }
    alias memoize!_dfs dfs;
    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;
        int first;
        for (int k = 0; 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 + 1, " ", ans);
        }
    }
}