#include<iostream>
#include<string>
#include<vector>
#include <map>
#include <cmath>
#define reps(i,n, m) for(int i=int(n); i<int(m);i++)
#define rep(i,n) reps(i,0,n)
using namespace std;
typedef pair<int, int> P;
const int inf = 500000000;
int sx, sy, gx, gy;
int h, w;
vector<string> vec;
vector<P> mp[5];
vector<int> val[5];
int dp[5][5][1010];
int dist(int x1, int y1, int x2, int y2) {
	return abs(x1-x2) + abs(y1-y2);
}
int main() {
	while(cin>>w>>h && h+w) {
		vec.clear();
		rep(i,5) {
			mp[i].clear();
			val[i].clear();
		}
		rep(i,5){
			rep(j,5){
				rep(k,1010)dp[i][j][k] =inf;
			}
		}
		rep(i, h){
			string temp;
			cin>>temp;
			vec.push_back(temp);
			rep(j,w){
				switch(vec[i][j]) {
				case 'S':
					sx = i; sy = j;
					break;
				case 'G':
					gx = i; gy = j;
					break;
				case '.':
					break;
				default:
					int num = (int) (vec[i][j] -'1');
					mp[num].push_back(P(i, j));
					break;
				}
			}
		}
		int ansCol = 0;
		int ansDist = inf;
		rep(rest, 4) {
			for (int col = 0; col<5;col++) {
				rep(i, mp[col].size()){
					if (rest == 0) {
						dp[rest][col][i] = dist(gx, gy, mp[col][i].first, mp[col][i].second);
					} else { //rest<4
						rep(j, mp[(col+1)%5].size()){
							int x1 = mp[col][i].first;
							int y1 = mp[col][i].second;
							int x2 = mp[(col+1)%5][j].first;
							int y2 = mp[(col+1)%5][j].second;
							int d = dist(x1, y1, x2, y2);
							dp[rest][col][i] = min(dp[rest][col][i], dp[rest-1][(col+1)%5][j]+d);
						}
					}
				}
			}
		}
		rep(col, 5) {
			int d = inf;
			int nc = (col+1)%5;
			rep(i, mp[nc].size()) {
				int ds = dist(sx, sy, mp[nc][i].first, mp[nc][i].second);
				d = min(d, dp[3][nc][i]+ds);
			}
			if (d <ansDist){
				ansDist = d;
				ansCol = col;
			}
		}
		if (ansDist == inf) {
			cout<<"NA"<<endl;
		} else {
			cout <<ansCol+1<<" "<<ansDist<<endl;
		}
	}
}