#include<iostream>
#include<map>
#include<deque>
#include<cstring>
#include<cstdlib>
using namespace std;
struct board{
	char s[14];
	int z1,z2;
	bool operator<(const board& rhs)const{return strcmp(s,rhs.s)<0;}
};
int main(){
	int d[13][5]={
		{2,-1},			//0
		{2,5,-1},		//1
		{0,1,3,6,-1},	//2
		{2,7,-1},		//3
		{5,-1},			//4
		{1,4,6,9,-1},	//5
		{2,5,7,10,-1},	//6
		{3,6,8,11,-1},	//7
		{7,-1},			//8
		{5,10,-1},		//9
		{6,9,11,12,-1},	//10
		{7,10,-1},		//11
		{10,-1},		//12
	};
	int gx[]={2,1,2,3,0,1,2,3,4,1,2,3,2};
	int gy[]={0,1,1,1,2,2,2,2,2,3,3,3,4};
	board goal;
	strcpy(goal.s,"0123456789:;0");
	for(;;){
		typedef map<board,int>SM;
		SM stepmap;
		deque<board> que;
		board b0;
		b0.z1=b0.z2=-1;
		for(int i=0;i<13;i++){
			int v;
			cin>>v;
			if(v==-1)
				return 0;
			b0.s[i]='0'+v;
			if(v==0){
				if(b0.z1==-1)
					b0.z1=i;
				else
					b0.z2=i;
			}
		}
		b0.s[13]=0;
		que.push_back(b0);
		stepmap[b0]=1;
		while(!que.empty()){
			board b=que.front();
			if(strcmp(b.s,goal.s)==0){
				break;
			}
			que.pop_front();
			int dist=0;
			for(int i=0;i<13;i++){
				int v=b.s[i]-'0';
				if(v){
					dist+=abs(gx[v]-gx[i])+abs(gy[v]-gy[i]);
				}
			}
			int step=stepmap[b];
			if(dist+step<=20){
				for(int i=0;d[b.z1][i]!=-1;i++){
					board bn=b;
					bn.z1=d[b.z1][i];
					if(bn.z1!=bn.z2){
						swap(bn.s[b.z1],bn.s[bn.z1]);
						int&ns=stepmap[bn];
						if(!ns){
							ns=step+1;
							que.push_back(bn);
						}
					}
				}
				for(int i=0;d[b.z2][i]!=-1;i++){
					board bn=b;
					bn.z2=d[b.z2][i];
					if(bn.z2!=bn.z1){
						swap(bn.s[b.z2],bn.s[bn.z2]);
						int&ns=stepmap[bn];
						if(!ns){
							ns=step+1;
							que.push_back(bn);
						}
					}
				}
			}
		}
		if(stepmap[goal]==0)
			cout<<"NA "<<endl;
		else
			cout<<stepmap[goal]-1<<endl;
	}
}