#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
ull B = 1000000007ull;
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[12]={0,1,1,1,2,2,2,2,2,3,3,3};
int py[12]={0,1,2,3,0,1,2,3,4,0,1,2};

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;
}
set<ull> s;
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);
}
int bfs(State st)
{
	if(check(st))return 0;
	queue<State> q;
	q.push(st);
	while(!q.empty())
	{
		State A = q.front();
		q.pop();
		if(A.t>20)return 21;
		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 p = hash(B);
					if(s.find(p)!=s.end())continue;
					s.insert(p);
					if(check(B))return B.t;
					q.push(B);
				}
			}
		}
	}
	return 21;
}
int main()
{
	while(1)
	{
		State st;
		s.clear();
		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;
		int ans = bfs(st);
		if(ans>20)printf("NA\n");
		else printf("%d\n",ans);
	}
	end:;
	return 0;
}