#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int lim = 20;
const vector<int> bx = { 0, 4, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3 };
const vector<int> by = { 2, 2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3 };
struct state {
	vector<int> px, py;
	int cost, rem, last1, last2;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost + s1.rem != s2.cost + s2.rem ? s1.cost + s1.rem > s2.cost + s2.rem : s1.rem > s2.rem;
}
int eval(vector<int> px, vector<int> py) {
	int ret = 0;
	for (int i = 2; i < 13; ++i) {
		ret += abs(px[i] - bx[i]) + abs(py[i] - by[i]);
	}
	return ret;
}
int main() {
	int x;
	while (cin >> x, x != -1) {
		vector<int> vx(13), vy(13);
		int zc = 0;
		vx[x == 0 ? zc : x + 1] = bx[0];
		vy[x == 0 ? zc : x + 1] = by[0];
		if (x == 0) ++zc;
		for (int i = 1; i < 13; ++i) {
			cin >> x;
			vx[x == 0 ? zc : x + 1] = bx[i == 12 ? 1 : i + 1];
			vy[x == 0 ? zc : x + 1] = by[i == 12 ? 1 : i + 1];
			if (x == 0) ++zc;
		}
		priority_queue<state> que;
		que.push(state{ vx, vy, 0, eval(vx, vy), -1, -1 });
		int ans = -1;
		while (!que.empty()) {
			state u = que.top();
			que.pop();
			if (u.rem == 0) {
				ans = u.cost;
				break;
			}
			for (int i = 0; i < 2; ++i) {
				for (int j = 2; j < 13; ++j) {
					if (i == u.last1 && j == u.last2) continue;
					if (abs(u.px[i] - u.px[j]) + abs(u.py[i] - u.py[j]) == 1) {
						swap(u.px[i], u.px[j]);
						swap(u.py[i], u.py[j]);
						int ev = eval(u.px, u.py);
						if (u.cost + ev + 1 <= lim) {
							que.push(state{ u.px, u.py, u.cost + 1, eval(u.px, u.py), i, j });
						}
						swap(u.px[i], u.px[j]);
						swap(u.py[i], u.py[j]);
					}
				}
			}
		}
		if (ans != -1) cout << ans << endl;
		else cout << "NA" << endl;
	}
	return 0;
}
