#include <iostream>
#include <vector>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a)
{
	os<<'[';
	rep(i,a.size())
		os<<(i?" ":"")<<a[i];
	return os<<']';
}

ostream& operator<<(ostream& os,const pii& a)
{
	return os<<'('<<a.first<<','<<a.second<<')';
}

int getdist(pii a,pii b)
{
	return abs(a.first-b.first)+abs(a.second-b.second);
}

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		
		pii start,goal;
		vector<vector<pii> > ps(5);
		rep(i,h) rep(j,w){
			if(grid[i][j]=='S')
				start=pii(i,j);
			if(grid[i][j]=='G')
				goal=pii(i,j);
			if(isdigit(grid[i][j]))
				ps[grid[i][j]-'1'].emplace_back(i,j);
		}
		
		vvi dp(5);
		rep(i,5)
			dp[i].resize(ps[i].size());
		
		pii res(INFTY,-1);
		rep(f,5){
			rep(i,5)
				fill(all(dp[i]),INFTY);
			rep(i,dp[(f+1)%5].size())
				dp[(f+1)%5][i]=getdist(start,ps[(f+1)%5][i]);
			repi(i,2,5){
				vector<pii> &ps0=ps[(f+i-1)%5],&ps1=ps[(f+i)%5];
				vi &dp0=dp[(f+i-1)%5],&dp1=dp[(f+i)%5];
				rep(j,dp0.size()) rep(k,dp1.size())
					dp1[k]=min(dp1[k],dp0[j]+getdist(ps0[j],ps1[k]));
			}
			int tmp=INFTY;
			rep(i,dp[(f+4)%5].size())
				tmp=min(tmp,dp[(f+4)%5][i]+getdist(ps[(f+4)%5][i],goal));
			res=min(res,pii(tmp,f));
		}
		if(res.second==-1)
			cout<<"NA"<<endl;
		else
			cout<<res.second+1<<' '<<res.first<<endl;
	}
	
	return 0;
}