#import<iostream>
#import<map>
#import<queue>
#import<cstdlib>
#import<cstring>
using namespace std;struct B{int z[2];char s[14];bool operator<(const B&r)const{return strcmp(s,r.s)<0;}};main(){int a[13][5]={{2,-1},{2,5,-1},{0,1,3,6,-1},{2,7,-1},{5,-1},{1,4,6,9,-1},{2,5,7,10,-1},{3,6,8,11,-1},{7,-1},{5,10,-1},{6,9,11,12,-1},{7,10,-1},{10,-1},},gx[]={2,1,2,3,0,1,2,3,4,1,2,3,2},gy[]={0,1,1,1,2,2,2,2,2,3,3,3,4},v,d,s,i,j;B g={0,0,"0123456789:;0"};for(;;){map<B,int>m;queue<B>q;B b={-1,-1};for(i=0;i<13;i++){cin>>v;if(v<0)return 0;b.s[i]=48+v;if(!v)b.z[b.z[0]!=-1]=i;}b.s[13]=0;m[b]=1;for(q.push(b);!q.empty();q.pop()){B&b=q.front();if(!strcmp(b.s,g.s))break;d=0;for(i=13;i--;){v=b.s[i]-48;if(v)d+=abs(gx[v]-gx[i])+abs(gy[v]-gy[i]);}s=m[b];if(s+d<22)for(j=2;j--;)for(i=0;~a[b.z[j]][i];i++){B n=b;n.z[j]=a[b.z[j]][i];if(n.z[j]-n.z[1-j]){swap(n.s[b.z[j]],n.s[n.z[j]]);int&b=m[n];if(!b)b=s+1,q.push(n);}}}printf(m[g]?"%d\n":"NA\n",m[g]-1);}}