#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int dx[13][4]={
  {3,0,0,0},
  {3,6,0,0},
  {1,2,4,6},
  {3,8,0,0},
  {6,0,0,0},
  {2,5,7,10},
  {3,6,8,11},
  {4,7,9,12},
  {8,0,0,0},
  {6,11,0,0},
  {6,10,12,13},
  {8,11,0,0},
  {11,0,0,0}
};
map<ll,int> mp;
ll Compress(int p[]){
  ll ans=0;
  for(int i=0;i<13;i++){
    ans*=13;
    ans+=p[i];
  }
  return ans;
}

int unzip[13];
void Unzip(ll x){
  for(int i=0;i<13;i++){
    unzip[12-i]=x%13;
    x/=13;
  }
}

int beflen=0;
queue<pair<ll,int> >Q;
void BFS(int p[],int len){
  //if(len!=beflen){cout<<len<<endl;beflen=len;}
  ll tmp=Compress(p);
  mp[tmp]=len;
  if(len==21)return;
  lol(i,13){
    if(p[i]==0){
      lol(j,4){
	int t=dx[i][j];
	if(t==0)break;
	t--;
	if(p[t]!=0){
	  swap(p[i],p[t]);
	  tmp=Compress(p);
	  if(mp[tmp]>0)continue;
	  Q.push(make_pair(tmp,len+1));
	  swap(p[i],p[t]);
	}
      }
    }
  }
}
int main(){
  int p[13];
  lol(i,13)p[i]=i;p[12]=0;
  Q.push(make_pair(Compress(p),1));
  while(!Q.empty()){
    ll data=Q.front().first;
    int len=Q.front().second;
    Q.pop();
    if(mp[data]>0)continue;
    Unzip(data);
    BFS(unzip,len);
  }
  while(cin>>p[0]&&p[0]!=-1){
    for(int i=1;i<13;i++)cin>>p[i];
    ll tmp=Compress(p);
    int cost=mp[tmp];
    if(cost==0)cout<<"NA"<<endl;
    else cout<<cost-1<<endl;
  }
  return 0;
}