#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem0215 : Pachimon Creature **/
int dp[5][1024];

vector<vector<PII> > list(5);

int dist(PII a, PII b)
{
	return abs(a.first - b.first) + abs(a.second - b.second);
}

int solve(int old, int idx, int got)
{
	if (got == 5) return 0;
	
	if (dp[got][idx] != -1)
		return dp[got][idx];
	
	int next = (old+1)%5;
	
	
	int res = INF;
	for (int i=0; i<list[next].size(); i++) {
		res = min(res, solve(old, i, got+1) + dist(list[old][idx], list[next][i]));
	}
	
	return dp[got][idx] = res;
}

int main()
{
	int W, H;
	while (cin>>W>>H, W||H) {
		for (int i=0; i<5; i++) list[i].clear();
		
		vector<string> field(H);
		rep(i, H) {
			cin>>field[i];
		}
		
		PII sp, gp;
		rep(y, H) {
			rep(x, W) {
				if (field[y][x] == 'S') {
					sp = PII(x, y);
				} else if (field[y][x] == 'G') {
					gp = PII(x, y);
				} else if (isdigit(field[y][x])) {
					int n = field[y][x] - '1';
					list[n].push_back(PII(x, y));
				}
			}
		}
		
		int ans = INF, ansFirst=-1;
		rep(first, 5) {
			memset(dp, -1, sizeof(dp));
			
			for (int i=0; i<list[first].size(); i++) {
				int res = solve(first, i, 1)+ dist(sp, list[first][i]);
				if (ans > res) {
					ans = res;
					ansFirst = first+1;
				}
			}
		}
		
		if (ans < INF) {
			cout << ansFirst << " " << ans << endl;
		} else {
			cout << "NA" << endl;
		}
	}
}