#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

vector<vector<int>>ans = vector<vector<int>>{
	vector<int>{-1,-1,-1,-1,-1,-1,-1},
	vector<int>{-1,-1,-1,0,-1,-1,-1},
	vector<int>{-1,-1,1,2,3,-1,-1},
	vector<int>{-1,4,5,6,7,8,-1},
	vector<int>{-1,-1,9,10,11,-1,-1},
	vector<int>{-1,-1,-1,0,-1,-1,-1},
	vector<int>{-1,-1,-1,-1,-1,-1,-1},
};

#include<unordered_map>
class HashVI {  // ???????????\??¢??°???????????§??????
public:
	size_t operator()(const vector<int> &x) const {
		const int C = 997;      // ?´???°
		size_t t = 0;
		for (int i = 0; i != x.size(); ++i) {
			t = t * C + x[i];
		}
		return t;
	}
	size_t operator()(const vector<vector<int>> &x) const {
		const int C = 997;      // ?´???°
		size_t t = 0;
		for (int i = 0; i != x.size(); ++i) {
			for (int j = 0; j < x[i].size(); ++j) {
				t = t * C + x[i][j];
			}
		}
		return t;
	}
};
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
int aaa=21;
void solve(vector<vector<int>>&start,const int turn ) {
	if (aaa <= turn)return;
	if (start == ans) {
		aaa = min(aaa, turn);
	}
	else {
		for (int i = 1; i < 6; ++i) {
			for (int j = 1; j < 6; ++j) {
				if (start[i][j] == 0) {
					for (int way = 0; way < 4; ++way) {
						if (start[i + dy[way]][j + dx[way]]>0) {
							swap(start[i][j],start[i + dy[way]][j + dx[way]]);
							if (start == ans) {
								aaa = min(aaa, turn);
							}
							else {

								solve(start, turn+1);
							}
							swap(start[i][j], start[i + dy[way]][j + dx[way]]);
						}
					}
				}
			}
		}
	}
	
}

int main() {
	while (1) {
		int a; cin >> a;
		aaa = 21;
		if (a == -1)break;
		vector<vector<int>>puzzle(7, vector<int>(7,-1));
		puzzle[1][3] = a;
		for (int i = 2; i <= 5; ++i) {
			for (int j = 3 - (2-(abs(i - 3))); j <= 3 + (2-abs(i - 3)); ++j) {
				cin >> puzzle[i][j];
			}
		}
		if (puzzle == ans) {
			cout << 0 << endl;
		}
		else {

			solve(puzzle, 1);
			if (aaa == 21)cout << "NA" << endl;
			else cout << aaa << endl;
		}
	}
	return 0;
}