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

struct P {
    int y, x;
}

void main() {
    int X, Y; 
    string[] F;
    char next(char c) {
        if (c == '5') return '1';
        else return cast(char)(c + 1);
    }
    char prev(char c) {
        if (c == '1') return '5';
        else return cast(char)(c - 1);
    }
    int dist(int y1, int x1, int y2, int x2) {
        return abs(y1 - y2) + abs(x1 - x2);
    }
    int dfs(int y, int x, char last) {
        char cur = F[y][x];
        if (cur == last) {
            foreach (i; 0 .. Y)
                foreach (j; 0 .. X)
                    if (F[i][j] == 'G') 
                        return dist(y, x, i, j);
            throw new Error("Gがない");
        }
        char n = next(cur);
        int ans = int.max / 2;
        foreach (i; 0 .. Y) 
            foreach (j; 0 .. X) 
                if (F[i][j] == n) 
                    ans = min(ans, dfs(i, j, last) + dist(y, x, i, j));
        return ans;
    }
    while (readf("%d %d\n", &X, &Y), X || Y) {
        F = new string[Y];
        foreach (ref L; F) L = readln.chomp;
        int sy, sx;
findS:  foreach (i; 0 .. Y) 
            foreach (j; 0 .. X)
                if (F[i][j] == 'S') {
                    sy = i;
                    sx = j;
                    break findS;
                }
        int ans = int.max / 2;
        char first = '0';
        for (char k = '1'; k <= '5'; k++)
            foreach (i; 0 .. Y)
                foreach (j; 0 .. X)
                    if (F[i][j] == next(k)) {
                        int c = dfs(i, j, prev(k)) + dist(sy, sx, i, j);
                        if (ans > c) {
                            ans = c;
                            first = k;
                        }
                    }
        if (first == '0') {
            writeln("NA");
        } else {
            writeln(first, " ", ans);
        }
    }
}