#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 solve(const vector<vector<int>>&start) {
	if (start == ans)return 0;
	set<vector<vector<int>>>mp;
	mp.emplace(start);
	for (int t = 0; t < 20; ++t) {
		set<vector<vector<int>>>nextmp;
		for (auto m : mp) {
			for (int i = 1; i < 6; ++i) {
				for (int j = 1; j < 6; ++j) {
					if (m[i][j] == 0) {
						for (int way = 0; way < 4; ++way) {
							if (m[i + dy[way]][j + dx[way]]>0) {
								swap(m[i][j], m[i + dy[way]][j + dx[way]]);
								if (m == ans)return t + 1;
								nextmp.emplace(m);
								swap(m[i][j], m[i + dy[way]][j + dx[way]]);
							}
						}
					}
				}
			}
		}
		mp = nextmp;
	}
	return -1;
}

int main() {
	while (1) {
		int a; cin >> a;
		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];
			}
		}
		int ans = solve(puzzle);
		if (ans == -1)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}