#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

const int N = 13;
const vector<vector<int>> NEXT = {
    {2},
    {2, 5},
    {0, 1, 3, 6},
    {2, 7},
    {5},
    {1, 4, 6, 9},
    {2, 5, 7, 10},
    {3, 6, 8, 11},
    {7},
    {5, 10},
    {6, 9, 11, 12},
    {7, 10},
    {10},
};

class Node {
public:
    vector<int> puzzle;
    int depth;
    Node(const vector<int>& p, int d) :puzzle(p), depth(d) {}
};

map<vector<int>, int> memo1;
map<vector<int>, int> memo2;

void bfs(const vector<int>& puzzle, map<vector<int>, int>& memo) {
    queue<Node> q;
    q.push(Node(puzzle, 0));
    while(!q.empty()) {
        Node current(q.front()); q.pop();
        if(current.depth > 1) continue;
        if(memo.count(current.puzzle)) continue;
        memo[current.puzzle] = current.depth;
        for(int i = 0; i < N; ++i) {
            if(current.puzzle[i] != 0) continue;
            for(const auto& j: NEXT[i]) {
                vector<int> next(current.puzzle);
                swap(next[i], next[j]);
                q.push(Node(next, current.depth + 1));
            }
        }
    }
}

int main() {
    vector<int> complete = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0};
    vector<int> puzzle(N);
    bfs(complete, memo1);
    while(cin >> puzzle[0], puzzle[0] != -1) {
        for(int i = 1; i < N; ++i) cin >> puzzle[i];
        memo2.clear();
        bfs(puzzle, memo2);
        int answer = 21;
        for(auto& i: memo1) if(memo2.count(get<0>(i))) answer = min(answer, get<1>(i) + memo2[get<0>(i)]);
        if(answer > 20) cout << "NA" << endl;
        else cout << answer << endl;
    }
}