#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

typedef struct{
  vector<int> in;
  int s1,s2;
}state;

vector<int> se[13];

void pr(vector<int> in){
  if(in.size()!=13)return;

  printf("      %3d\n",in[0]);
  printf("   %3d%3d%3d\n",in[1],in[2],in[3]);
  printf("%3d%3d%3d%3d%3d\n",in[4],in[5],in[6],in[7],in[8]);
  printf("   %3d%3d%3d\n",in[9],in[10],in[11]);
  printf("      %3d\n",in[12]);
  puts("");
}

main(){
  int p;
  vector<int> goal(13);
  rep(i,11)goal[i+1]=i+1;
  //cout<<print_array(goal)<<endl;

  se[0].pb(2);
  se[1].pb(2);
  se[1].pb(5);
  se[2].pb(0);
  se[2].pb(1);
  se[2].pb(3);
  se[2].pb(6);
  se[3].pb(2);
  se[3].pb(7);
  se[4].pb(5);
  se[5].pb(1);
  se[5].pb(4);
  se[5].pb(6);
  se[5].pb(9);
  se[6].pb(2);
  se[6].pb(5);
  se[6].pb(7);
  se[6].pb(10);
  se[7].pb(3);
  se[7].pb(6);
  se[7].pb(8);
  se[7].pb(11);
  se[8].pb(7);
  se[9].pb(5);
  se[9].pb(10);
  se[10].pb(6);
  se[10].pb(9);
  se[10].pb(11);
  se[10].pb(12);
  se[11].pb(7);
  se[11].pb(10);
  se[12].pb(10);
  
  while(cin>>p){
    if(p==-1)break;
    vector<int> in;
    in.pb(p);
    rep(i,12){
      cin>>p;
      in.pb(p);
    }

    set<vector<int> > app;

    queue<pair<int,vector<int> > > Q;
    app.insert(in);
    Q.push(mp(0,in));
    int ans=21;

    while(!Q.empty()){
      vector<int> cvec=Q.front().S;
      int ccost=Q.front().F;
      Q.pop();
      //cout<<print_array(cvec)<<endl;
      //pr(cvec);
      if(ccost>3)break;
      if(ccost>20)break;
      if(cvec==goal){
	ans=ccost;
	break;
      }
      rep(i,cvec.size()){
	if(!cvec[i]){
	  rep(j,se[i].size()){
	    if(cvec[se[i][j]]){
	      swap(cvec[se[i][j]],cvec[i]);
	      if(!app.count(cvec)){
		app.insert(cvec);
		Q.push(mp(ccost+1,cvec));
	      }
	      swap(cvec[se[i][j]],cvec[i]);
	    }
	  }
	}
      }
    }
    if(ans==21)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
}