#include <iostream>
#include <vector>
#include <cctype>
#include <queue>
#include <functional>
#include <cmath>
#include <algorithm>

constexpr int MAX = 1000, INF = (int)1e9;

struct edge {
	int toX_, toY_;
	edge() = default;
	edge(int x, int y) : toX_(x), toY_(y) {}
};

struct Node {
	int cost_, x_, y_, num_, cnt_;
	Node() = default;
	Node(int cost, int x, int y, int num, int cnt) : cost_(cost), x_(x), y_(y), num_(num), cnt_(cnt) {}
	
	bool operator<(const Node& rhs) const {
		return (cost_ == rhs.cost_) ? cnt_ < rhs.cnt_ : cost_ < rhs.cost_;
	}

	bool operator > (const Node& rhs) const {
		return (cost_ == rhs.cost_ ? cnt_ > rhs.cnt_ : cost_ > rhs.cost_);
	}
};

int w, h;
int sx, sy, gx, gy;
std::vector<edge> G[5];
int d[MAX][MAX];

int dijkstra(int num) {
	for (int j = 0; j < h; ++j) {
		for (int k = 0; k < w; ++k)
			d[j][k] = INF;
	}

	std::priority_queue<Node, std::vector<Node>,std::greater<Node>> que;

	d[sy][sx] = 0;
	que.emplace(0, sx, sy, num, 1);

	while (!que.empty()) {
		Node node = que.top(); que.pop();
		if (node.cost_ > d[node.y_][node.x_])
			continue;
		if (node.cnt_ == 5)
			return d[node.y_][node.x_] + abs(gx - node.x_) + abs(gy - node.y_);
		edge e;
		for (int i = 0; i < G[node.num_].size(); ++i) {
			e = G[node.num_][i];
			if (d[e.toY_][e.toX_] > d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_)) {
				d[e.toY_][e.toX_] = d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_);
				que.emplace(d[e.toY_][e.toX_], e.toX_, e.toY_, (node.num_ + 1) % 5, node.cnt_ + 1);
			}
		}
	}
	return -1;
}

int main() {
	while (1) {
		std::cin >> w >> h;
		if (w + h == 0)
			break;
		for (int i = 0; i < 5; ++i)
			G[i].clear();
		char ch;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				std::cin >> ch;
				if (ch == 'S') {
					sx = j;
					sy = i;
				}
				else if (ch == 'G') {
					gx = j;
					gy = i;
				}
				if (std::isdigit(ch)) {
					int num = atoi(&ch);
					--num;
					G[(num + 4) % 5].emplace_back(j, i);
				}
			}
		}
		int ans = INF, v, res;
		for (int i = 0; i < 5; ++i) {
			res = dijkstra(i);
			if (res != -1 && ans > res) {
				ans = res;
				v = i;
			}
		}
		
		if (ans == INF)
			std::cout << "NA" << std::endl;
		else
			std::cout << v + 1 << ' ' << ans << std::endl;
	}
	return 0;
}