#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct Point {
  int y, x;
  Point(){}
  Point(int y, int x):y(y), x(x){}
  int operator-(Point p) {
    return abs(y-p.y)+abs(x-p.x);
  }
};

int dp[5][1001];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int w, h;
  while(cin >> w >> h, w+h) {
    Point s, g;
    vector<Point> ps[5];
    set<char> st;
    rep(i, h) rep(j, w) {
      char c;
      cin >> c;
      if(c == '.') continue;
      Point p(i, j);
      if(c == 'S') s = p;
      else if(c == 'G') g = p;
      else if(isdigit(c)) ps[c-'0'-1].push_back(p);
      st.insert(c);
    }
    /*
    if(st.size() < 7) {
      cout << "NA" << endl;
      return 0;
    }
    */
    int ans = inf;
    int sel = -1;
    rep(i, 5) {
      fill(dp[0], dp[5], inf);
      dp[i][0] = 0;
      rep(j, 4) {
	int prev = (i+j)%5;
	int next = (i+j+1)%5;
	int sz = (prev == i ? 1 : ps[prev].size());
	rep(k, sz) {
	  if(dp[prev][k] == inf) continue;
	  int val = dp[prev][k];
	  Point p = (prev == i ? s : ps[prev][k]);
	  rep(l, ps[next].size()) {
	    Point q = ps[next][l];
	    chmin(dp[next][l], val + (q-p));
	  }
	}
      }
      int last = (i+4)%5;
      rep(j, ps[last].size()) {
	if(dp[last][j] == inf) continue;
	Point p = ps[last][j];
	int val = dp[last][j] + (g-p);
	if(val < ans) {
	  ans = val;
	  sel = i+1;
	}
      }
    }
    if(ans == inf) cout << "NA" << endl;
    else cout << sel << " " << ans << endl;
  }

  return 0;
}