#include<stdio.h>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
int p[15];
struct wolf{
	int m[13];
};
inline bool operator <(const wolf &a,const wolf &b){
	for(int i=0;i<13;i++)if(a.m[i]!=b.m[i])return a.m[i]<b.m[i];
	return false;
}
int g[13][4]={
{2,-1,-1,-1},
{2,5,-1,-1},{0,1,3,6},{2,7,-1,-1},
{5,-1,-1,-1},{1,4,6,9},{2,5,7,10},{3,6,8,11},{7,-1,-1,-1},
{5,10,-1,-1},{6,9,11,12},{7,10,-1,-1},
{10,-1,-1,-1}
};
int row[]={0,1,1,1,2,2,2,2,2,3,3,3,4};
int col[]={2,1,2,3,0,1,2,3,4,1,2,3,2};
int ABS(int a){return max(a,-a);}
int main(){
	while(scanf("%d",p),~p[0]){
		for(int i=1;i<13;i++)scanf("%d",p+i);
		set<wolf>S;
		wolf st;
		for(int i=0;i<13;i++)st.m[i]=p[i];
		queue<pair<wolf,int> > Q;
		S.insert(st);
		Q.push(make_pair(st,0));
		bool yet=true;
		while(Q.size()){
			wolf at=Q.front().first;
			int cost=Q.front().second;
			Q.pop();
			bool ok=true;
			for(int i=1;i<12;i++)if(at.m[i]!=i)ok=false;
			if(ok){
				yet=false;
				printf("%d\n",cost);
				break;
			}
			int now=cost;
			for(int i=0;i<13;i++)if(at.m[i]){
				now+=ABS(row[i]-row[at.m[i]])+ABS(col[i]-col[at.m[i]]);
			}
			if(now>=20)continue;
			for(int i=0;i<13;i++)if(!at.m[i]){
				for(int j=0;j<4;j++)if(~g[i][j]){
					swap(at.m[i],at.m[g[i][j]]);
					if(!S.count(at)){
						S.insert(at);
						Q.push(make_pair(at,cost+1));
					}
					swap(at.m[i],at.m[g[i][j]]);
				}
			}
		}
		if(yet)printf("NA\n");
	}
}