#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef vector<Int> vInt;
typedef pair<int,int> pint;
typedef pair<Int,Int> pInt;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef vector<pInt> vpInt;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,1,-1,-1,0};
const int dy[]={0,0,1,-1,1,-1,1,-1,0};

vstring m;
vpint p[10];
vector<pair<int, pint> > a, b;

int main() {
	int x, y;
	IL {
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		m.clear();
		rep (i, y) {
			string s;
			cin >> s;
			m.PB(s);
		}
		int sx, sy, gx, gy;
		rep (i, 10) p[i].clear();
		rep (i, y) rep (j, x) {
			if (m[i][j] == 'S') {
				sx = j;
				sy = i;
			}
			if (m[i][j] == 'G') {
				gx = j;
				gy = i;
			}
			if (isdigit(m[i][j])) {
				p[m[i][j] - '1'].PB(MP(i, j));
			}
		}
		int res = INF, type;
		rep (i, 5) {
			a.clear();
			a.PB(MP(0, MP(sy, sx)));
			repn (j, 1, 5) {
				b.clear();
				rep (l, sz(p[(i + j) % 5])) {
					int mn = INF;
					rep (k, sz(a)) {
						chmin(mn, a[k].first + abs(a[k].second.first - p[(i + j) % 5][l].first) + abs(a[k].second.second - p[(i + j) % 5][l].second));
					}
					b.PB(MP(mn, p[(i + j) % 5][l]));
//cout << i <<" " << j << " " << mn << " " << p[(i + j) % 5][l].first << " " << p[(i + j) % 5][l].second << endl;
				}
				a = b;
			}
			rep (j, sz(b)) {
				int dis = b[j].first + abs(b[j].second.first - gy) + abs(b[j].second.second - gx);
				if (dis < res) {
					res = dis;
					type = i;
//cout << i << " " << dis << endl;
				}
			}
		}
		if (res == INF) cout << "NA\n";
		else cout << type + 1 << " " << res << endl;
	}
	return 0;
}