#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
class NODE{
public:
	vector<int> data;
	int depth;
	int e[2];
	NODE(int a[13],int d,int E[2]){
		data.resize(13);
		rep(i,13)data[i] = a[i];
		depth = d;
		rep(i,2)e[i] = E[i];
	}
	NODE(){
		depth = 0;
		data.resize(13);
	}
};

int di[13][10] = {
	{2,-1},
	{2,5,-1},
	{0,1,3,6,-1},
	{2,7,-1},
	{5,-1},
	{1,4,6,9,-1},
	{2,5,7,10,-1},
	{3,6,7,11,-1},
	{7},
	{5,10,-1},
	{6,9,11,12,-1},
	{7,10,-1},
	{10,-1}
};
int rx[] = {3,2,3,4,1,2,3,4,5,2,3,4,3};
int ry[] = {1,2,2,2,3,3,3,3,3,4,4,4,5};

int main(){
	while(1){
		int ret = 21;
		NODE fst; int cnt = 0;
		rep(i,13){
			if(cin >>fst.data[i] , fst.data[i] != -1){
				if(fst.data[i] == 0){
					fst.e[cnt] = i;
					cnt++;
				}
			}else{
				return 0;
			}
		}
		map< vector<int> , int > done[2];
		
		rep(x,2){
			queue<NODE> Q;
			if(x==0){
				Q.push(fst);
			}else{
				NODE a;
				rep(i,11)a.data[i+1] = i+1;
				a.e[0] = 0;
				a.e[1] = 12;
				Q.push(a);
			}	
			done[x][Q.front().data] = 0;
			while(Q.size()){
				NODE q = Q.front(); Q.pop();
				int mndist = 0;
				rep(i,13)mndist += abs(rx[q.data[i]]-rx[i]) + abs(ry[q.data[i]]-ry[i]);
				
				if(mndist > 30)continue;
				
				if(x == 1){
					if( done[0].find(q.data) != done[0].end() ){
						ret = q.depth + done[0][q.data] ;
						break;
					}
				}else{
					if( q.data[0] == 0 && q.data[1] == 1 && q.data[2] == 2 && q.data[3] == 3 && q.data[4] == 4 && q.data[5] == 5 && q.data[6] == 6 && q.data[7] == 7 &&
							q.data[8] == 8 && q.data[9] == 9 && q.data[10]==10 && q.data[11]==11 && q.data[12]==0
					){
						ret = q.depth;
						break;
					}
				}
				if(q.depth >= 10)continue;

				rep(o,2){
					for(int i=0;di[q.e[o]][i] != -1;i++){
						NODE next = q;
						next.e[o] = next.data[di[q.e[o]][i]];
						swap(next.data[q.e[o]] , next.data[di[q.e[o]][i]]);
						next.depth = q.depth + 1;
						
						if( done[x].find(next.data) == done[x].end() ){
							done[x][next.data] = next.depth;
							Q.push(next);
						}
					}
				}
			}
		}
		if(ret > 20){
			cout << "NA" << endl;
		}else{
			cout << ret << endl;
		}
	}
}