#include <bits/stdc++.h>
using namespace std;
const int pos_x[] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4};
const int pos_y[] = {2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2};
const int table[][5] = {
	{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, 8, 11, -1},
	{7, -1},
	{5, 10, -1},
	{6, 9, 11, 12, -1},
	{7, 10, -1},
	{10, -1},
};

struct Puzzle {
	vector<int> val;
	Puzzle(): val(13){}
	int score(){
		int res = 0;
		for (int i = 0; i < 13; i++){
			if (!val[i]) continue;
			int v = val[i];
			res += abs(pos_x[v] - pos_x[i]);
			res += abs(pos_y[v] - pos_y[i]);
		}
		return res;
	}
	void show(){
		for (int i = 0; i < 13; i++){
			printf("%d ", val[i]);
			if (i == 0 || i == 3 || i == 8 || i == 11 || i == 12){
				puts("");
			}
		}
	}
};

/*inline bool check(Puzzle &p)
{
	for (int i = 1; i <= 11; i++){
		if (p.val[i] != i) return false;
	}
	return true;
}*/

bool search(int d, Puzzle &p)
{
	if (p.score() == 0) return true;
	if (d == 0) return false;
	
	for (int i = 0; i < 13; i++){
		if (p.val[i]) continue;
		for (const int *to = &table[i][0]; ~(*to); to++){
			swap(p.val[i], p.val[*to]);
			//printf("%d %d\n", i, *to);
			//printf("%d\n", p.score());
			if (d - 1 - p.score() >= 0){
				if (search(d - 1, p)) return true;
			}
			swap(p.val[i], p.val[*to]);
		}
	}
	return false;
}

void solve(Puzzle &p)
{
	for (int d = 0; d <= 20; d++){
		if (search(d, p)){
			printf("%d\n", d);
			return;
		}
	}
	puts("NA");
}

int main()
{	
	Puzzle p;
	while (true){
		for (int i = 0; i < 13; i++){
			scanf("%d", &p.val[i]);
			if (p.val[i] == -1) return 0;
		}
		solve(p);
	}
}