#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <iostream>
using namespace std;

#define x first
#define y second
typedef pair<int,int> pii;

#define INF 1e9

int main() {
	int W, H;
	const int symbol[] = {'S', '1', '2', '3', '4', '5', 'G'};
	while(cin >> W >> H, W || H) {
		vector<string> in;
		for(int i = 0; i < H; i++) {
			string s;
			cin >> s;
			in.push_back(s);
		}
		vector<vector<pii> > vertex(7);
		for(int i = 0; i < in.size(); i++) {
			for(int j = 0; j < in[i].size(); j++) {
				for(int k = 0; k < 7; k++) {
					if(in[i][j] == symbol[k])
						vertex[k].push_back(pii(j,i));
				}
			}
		}

		pii ans(INF, 0);
		for(int i = 0; i < 5; i++) {
			vector<vector<int> > cost;
			for(int j = 0; j < 5; j++) {
				cost.push_back(vector<int>(vertex[j+1].size(), INF));
			}

			for(int j = 0; j < cost[(i+1)%5].size(); j++) {
				cost[(i+1)%5][j] = abs(vertex[(i+1)%5+1][j].x - vertex[0][0].x) + abs(vertex[(i+1)%5+1][j].y - vertex[0][0].y);
			}

			for(int j = 1; j < 4; j++) {
				for(int k = 0; k < cost[(i+j)%5].size(); k++) {
					for(int l = 0; l < cost[(i+j+1)%5].size(); l++) {
						cost[(i+j+1)%5][l] =
							min(cost[(i+j+1)%5][l], cost[(i+j)%5][k] + abs(vertex[(i+j)%5+1][k].x - vertex[(i+j+1)%5+1][l].x) + abs(vertex[(i+j)%5+1][k].y - vertex[(i+j+1)%5+1][l].y));
					}
				}
			}

			pii tmp(INF, 0);
			for(int j = 0; j < cost[(i+4)%5].size(); j++) {
				if(tmp.first > cost[(i+4)%5][j] + abs(vertex[(i+4)%5+1][j].x - vertex[6][0].x) + abs(vertex[(i+4)%5+1][j].y - vertex[6][0].y)) {
					tmp.first = cost[(i+4)%5][j] + abs(vertex[(i+4)%5+1][j].x - vertex[6][0].x) + abs(vertex[(i+4)%5+1][j].y - vertex[6][0].y);
					tmp.second = i;
				}
			}

			if(ans > tmp)
				ans = tmp;
		}
		if(ans.first == INF)
			cout << "NA" << endl;
		else
			cout << ans.second + 1 << " " << ans.first << endl;;
	}
}