#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef vector<xy_t> polygon;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

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

int memo[sz][6];
P pos[sz][7];
int cnt[7];

int cost(const P &p1, const P &p2){
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

void update(int cur, int nxt, int n){
	rep(i, cnt[cur]){
		rep(j, cnt[nxt]){
			memo[j][n+1] = min(memo[j][n+1], memo[i][n] + cost(pos[i][cur], pos[j][nxt]));
		}
	}
}

int main(){
	int X, Y;
	int num;
	char ch;
	while(cin >> X >> Y && (X || Y)){
		memset(cnt, 0, sizeof(cnt));
		rep(i, Y)rep(j, X){
			cin >> ch;
			if(ch == '.') continue;
			if(ch == 'S'){
				pos[cnt[0]++][0] = P(j, i);
			}else if(ch == 'G'){
				pos[cnt[6]++][6] = P(j, i);
			}else{
				num = ch - '0';
				pos[cnt[num]++][num] = P(j, i);
			}
		}
		int res = INF;
		int id = -1;

		rep(type, 5){
			fill(&memo[0][0], &memo[sz-1][5] + 1, INF);
			memo[0][0] = 0;
			rep(i, 5){
				int cur = 0, nx = 0;
				if(i == 0){
					cur = 0;
					nx = 1 + (type + i + 1) % 5;
				}else if(i == 4){
					cur = 1 + (type + i) % 5;
					nx = 6;
				}else{
					cur = 1 + (type + i) % 5;
					nx = 1 + (type + i + 1) % 5;
				}
				update(cur, nx, i);
			}
		
			if(memo[0][5] < res){
				res = memo[0][5];
				id = type;
			}
		}
		if(res == INF) cout << "NA" << endl;
		else cout << id+1 << " " << res << endl;
	}
	return 0;
}