#include<iostream>
#include<queue>
#include<map>
#include<vector>
using namespace std;
int px[13]={0,1,1,1,2,2,2,2,2,3,3,3,4},py[13]={2,1,2,3,0,1,2,3,4,1,2,3,2};
int xx[12]={0,1,1,1,2,2,2,2,2,3,3,3},yy[12]={0,1,2,3,0,1,2,3,4,1,2,3};
struct board{
	int p[13],a,b;
	bool operator<(const board&a)const
	{
		for(int i=0;i<13;i++)
		{
			if(p[i]!=a.p[i])return p[i]<a.p[i];
		}
		return false;
	}
	int distance()const
	{
		int ret=0;
		for(int i=0;i<13;i++)
		{
			if(p[i]==0)continue;
			ret+=abs(px[i]-xx[p[i]])+abs(py[i]-yy[p[i]]);
		}
		return ret;
	}
};
vector<int>D[13];
main()
{
	D[0].push_back(2);
	D[1].push_back(2);
	D[1].push_back(5);
	D[2].push_back(0);
	D[2].push_back(1);
	D[2].push_back(3);
	D[2].push_back(6);
	D[3].push_back(2);
	D[3].push_back(7);
	D[4].push_back(5);
	D[5].push_back(1);
	D[5].push_back(4);
	D[5].push_back(6);
	D[5].push_back(9);
	D[6].push_back(2);
	D[6].push_back(5);
	D[6].push_back(7);
	D[6].push_back(10);
	D[7].push_back(3);
	D[7].push_back(6);
	D[7].push_back(8);
	D[7].push_back(11);
	D[8].push_back(7);
	D[9].push_back(5);
	D[9].push_back(10);
	D[10].push_back(6);
	D[10].push_back(9);
	D[10].push_back(11);
	D[10].push_back(12);
	D[11].push_back(7);
	D[11].push_back(10);
	D[12].push_back(10);
	while(true)
	{
		board start;
		cin>>start.p[0];
		if(start.p[0]<0)break;
		for(int i=1;i<13;i++)cin>>start.p[i];
		start.a=start.b=-1;
		for(int i=0;i<13;i++)
		{
			if(start.p[i]==0)
			{
				if(start.a<0)start.a=i;
				else start.b=i;
			}
		}
		board goal;
		for(int i=0;i<12;i++)goal.p[i]=i;
		goal.p[12]=0;
		queue<board>P;
		P.push(start);
		map<board,int>M;
		M[start]=0;
		int ans=-1;
		while(!P.empty())
		{
			board now=P.front();P.pop();
			int c=M[now];
			if(c+now.distance()>20)continue;
			if(!(now<goal||goal<now))
			{
				ans=c;
				break;
			}
			for(int v:D[now.a])
			{
				int x=now.a,y=v;
				swap(now.p[x],now.p[y]);
				now.a=y;
				if(M.find(now)==M.end())
				{
					M[now]=c+1;
					P.push(now);
				}
				swap(now.p[x],now.p[y]);
				now.a=x;
			}
			for(int v:D[now.b])
			{
				int x=now.b,y=v;
				swap(now.p[x],now.p[y]);
				now.b=y;
				if(M.find(now)==M.end())
				{
					M[now]=c+1;
					P.push(now);
				}
				swap(now.p[x],now.p[y]);
				now.b=x;
			}
		}
		if(ans<0)cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
}

