#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;

const int MAX_S = 1001;
int W, H;
vector< pair<int, int> > V[5];

int sx, sy, gx, gy;

int cost(int x1, int y1, int x2, int y2) {
  return abs(x1-x2) + abs(y1-y2);
}

int rec(int x, int y, int step, int spc) {
  int res = 99999999;
  if(step == 4) {
    return cost(x, y, gx, gy);
  } else {
    int k = (spc + step + 1) % 5;
    for(int i = 0; i < V[k].size(); ++i) {
      res = min(res, rec(V[k][i].first, V[k][i].second, step+1, spc)
		+ cost(x, y, V[k][i].first, V[k][i].second));
    }
    return res;
  }
}

void solve() {
  int pc, minV;
  pc = -1;
  minV = 99999999;
  for(int i = 0; i < 5; ++i) {
    int newV = rec(sx, sy, 0, i);
    if(newV < minV) {
      minV = newV;
      pc = i;
    }
  }

  if(pc == -1) cout << "NA" << endl;
  else         cout << pc+1 << " " << minV << endl;
}

int main() {
  while((cin >> W >> H) && (W || H)) {
    for(int i = 0; i < 5; ++i) {
      V[i].clear();
    }
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	char c;
	cin >> c;
	if(c == 'S') {
	  sx = j;
	  sy = i;
	} else if(c == 'G') {
	  gx = j;
	  gy = i;
	} else if(c != '.') {
	  V[c-'0'-1].push_back(make_pair(j, i));
	}
      }
    }
    solve();
  }
  return 0;
}