// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1 << 28;
const ll MOD = 1000000007LL;

char board[1010][1010];

int rec[1010][1010][5];
int H, W;

struct Elem {
    int x, y, bit;
};
 
signed main() {
    while(cin >> W >> H, W || H) {
        int sx, sy, gx, gy;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                cin >> board[i][j];

                if(board[i][j] == 'S') sx = i, sy = j;
                if(board[i][j] == 'G') gx = i, gy = j;
                if(isdigit(board[i][j])) {
                    int c = board[i][j] - '0';
                    board[i][j] = (char)(c - 1 + '0');
                }
            }
        }

        const pair<int, int> NIL(INF, INF);
        pair<int, int> ans = NIL;

        for(int p=0; p<5; p++) {
            fill(rec[0][0], rec[H][0], INF);
            rec[sx][sy][0] = 0;

            queue<Elem> que;
            que.push(Elem{sx, sy, 0});

            while(que.size()) {
                Elem cur = que.front(); que.pop();
                int x = cur.x, y = cur.y, bit = cur.bit;
                if(x == gx and y == gy and bit == 4) break;

                for(int k=0; k<4; k++) {
                    int nx = x + dx[k], ny = y + dy[k];
                    if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
                    
                    int nbit = bit;
                    if(isdigit(board[nx][ny])) {
                        int c = (board[nx][ny] - '0' - p + 10) % 5;
                        bool ok = (bit + 1 >= c);
                        
                        if(!ok) continue;
                        nbit = max(bit, c);
                    }
                
                    if(rec[nx][ny][nbit] > rec[x][y][bit] + 1) {
                        rec[nx][ny][nbit] = rec[x][y][bit] + 1;
                        que.push(Elem{nx, ny, nbit});
                    }
                }
            }

            ans = min(ans, make_pair(rec[gx][gy][4], p+1));
        }
        if(ans.first == INF) cout << "NA" << endl;
        else cout << ans.second << " " << ans.first << endl;
    }
    return 0;
}
