#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
ull B = 1000000003ull;
int a[5]={2,1,0,1,2};
int b[5]={2,3,4,3,2};
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
int px[13]={0,1,1,1,2,2,2,2,2,3,3,3,0};
int py[13]={0,1,2,3,0,1,2,3,4,1,2,3,0};
 
struct State
{
    int f[5][5];
    int t;
};
ull hash(State x)
{
    ull t = 1ull;
    ull res = 0;
    for(int i=0;i<5;i++)
    {
        for(int j=a[i];j<=b[i];j++)
        {
            res += x.f[i][j]*t;
            t *= B;
        }
    }
    return res;
}
map<ull,int> mp;
set<ull> used;
bool check(State x)
{
    int cnt=1;
    for(int i=1;i<=3;i++)
    {
        for(int j=a[i];j<=b[i];j++)
        {
            if(x.f[i][j]!=cnt)return false;
            cnt++;
        }
    }
    return true;
}
bool cc(State x)
{
    int res = 0;
    for(int i=0;i<5;i++)
    {
        for(int j=a[i];j<=b[i];j++)
        {
            if(x.f[i][j])
            {
                int k = x.f[i][j];
                res += (abs(px[k]-i)+abs(py[k]-j));
            }
        }
    }
    return (res>20-x.t);
}
int ans = 21;
void bfs(State st)
{
    queue<State> q;
    mp[hash(st)]=0;
    q.push(st);
    while(!q.empty())
    {
        State A = q.front();
        q.pop();
        //cout << "koko" << endl;
        for(int i=0;i<5;i++)
        {
            for(int j=0;j<5;j++)
            {
                if(j<a[i]||b[i]<j)continue;
                if(A.f[i][j]==0)continue;
                for(int k=0;k<4;k++)
                {
                    int nx=i+dx[k],ny=j+dy[k];
                    if(nx<0||nx>=5||ny<0||ny>=5)continue;
                    if(ny<a[nx]||b[nx]<ny)continue;
                    if(A.f[nx][ny]!=0)continue;
                    State B = A;
                    swap(B.f[nx][ny],B.f[i][j]);
                    B.t++;
                    //cout << "a" << endl;
                    if(B.t>8)continue;
                    ull hb = hash(B);
                    if(mp.find(hb)!=mp.end())continue;
                    //cout << hb << endl;
                    mp[hb]=B.t;
                    q.push(B);
                }
            }
        }
    }
    //cout << "owari" << endl;
}
void bfs2(State st)
{
    queue<State> q;
    if(check(st)){ans=0;return;}
    q.push(st);
    while(!q.empty())
    {
        State A = q.front();
        q.pop();
        ull ha=hash(A); 
        if(mp.find(hash(A))!=mp.end()){ans = min(ans,A.t+mp[ha]);continue;}
        for(int i=0;i<5;i++)
        {
            for(int j=0;j<5;j++)
            {
                if(j<a[i]||b[i]<j)continue;
                if(A.f[i][j]==0)continue;
                for(int k=0;k<4;k++)
                {
                    int nx=i+dx[k],ny=j+dy[k];
                    if(nx<0||nx>=5||ny<0||ny>=5)continue;
                    if(ny<a[nx]||b[nx]<ny)continue;
                    if(A.f[nx][ny]!=0)continue;
                    State B = A;
                    swap(B.f[nx][ny],B.f[i][j]);
                    B.t++;
                    if(cc(B))continue;
                    ull hb = hash(B);
                    if(used.find(hb)!=used.end())continue;
                    used.insert(hb);
                    q.push(B);
                }
            }
        }
    }
}
int main()
{
    State end;
    int cnt=1;
    end.t=0;
    for(int i=0;i<5;i++)for(int j=0;j<5;j++)end.f[i][j]=-1;
    end.f[0][2]=0;
    end.f[4][2]=0;
    for(int i=1;i<=3;i++)for(int j=a[i];j<=b[i];j++)end.f[i][j]=cnt++;
    /*for(int i=0;i<5;i++)
    {
        for(int j=a[i];j<=b[i];j++)cout << end.f[i][j] << ' ';
        cout << endl;
    }*/
    bfs(end);
    while(1)
    {
        State st;
        used.clear();
        ans = 21;
        for(int i=0;i<5;i++)for(int j=0;j<5;j++)st.f[i][j]=-1;
        for(int i=0;i<5;i++)
        {
            for(int j=a[i];j<=b[i];j++)
            {
                cin >> st.f[i][j];
                if(st.f[i][j]==-1)goto end;
            }
        }
        st.t=0;
        bfs2(st);
        if(ans>20)printf("NA\n");
        else printf("%d\n",ans);
    }
    end:;
    return 0;
}