#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;

#define NONE -1

// »ÝÌóÔ
vector < vector <int> > F( 5, vector <int>(5,NONE) );
// S[
vector < vector <int> > GOAL( 5, vector <int>(5,NONE) );
// KâÏÝ
set < vector < vector <int> > > V;
// ó«Ìê
int empty_x[2];
int empty_y[2];
int now;

int getMD()
{
	int md = 0;
	for ( int i = 0; i < 5; i++ ) for ( int j = 0; j < 5; j++ )
	{
		if ( F[i][j] != GOAL[i][j] )
		{
			// T·
			bool found = false;
			for ( int k = 0; k < 5; k++ )
			{
				for ( int m = 0; m < 5; m++ )
				{
					//  Á½
					if ( F[i][j] == GOAL[k][m] )
					{
						md += abs(k-i) + abs(m-j);
						found = true;
						break;
					}
				}
				if ( found ) break;
			}
		}
	}
	return md;
}

bool search( int depth )
{
	if ( F == GOAL )
		return true;
	if ( now + getMD() > depth )
		return false;

	now++;
	for ( int e = 0; e < 2; e++ ) for ( int i = -1; i < 2; i++ ) for ( int j = -1; j < 2; j++ )
	{
		if ( i+j == 1 || i+j == -1 )
		{
			int ox = empty_x[e];
			int oy = empty_y[e];
			int tx = empty_x[e] + i;
			int ty = empty_y[e] + j;

			if ( ( tx >= 0 && tx <= 4 ) && ( ty >= 0 && ty <= 4 ) )
			{
				if ( F[ty][tx] != 0 && F[ty][tx] != NONE )
				{
					// ®©·
					swap( F[oy][ox], F[ty][tx] );

					// ¢JÌnÅ éÈçÎ
					if ( V.find( F ) == V.end() )
					{
						if ( search( depth ) )
							return true;
					}

					// ß·
					swap( F[oy][ox], F[ty][tx] );
				}
			}
		}
	}
	now--;

}

int main( void )
{
	while ( 1 )
	{
		// S[ðìé
		GOAL[0][2] = 0;
		for ( int i = 0; i < 3; i++ )
			GOAL[1][1+i] = i+1;
		for ( int i = 0; i < 5; i++ )
			GOAL[2][i] = 4 + i;
		for ( int i = 0; i < 3; i++ )
			GOAL[3][1+i] = 9 + i;
		GOAL[4][2] = 0;

		// üÍ
		cin >> F[0][2];
		if ( F[0][2] == -1 )
			break;
		for ( int i = 0; i < 3; i++ )
			cin >> F[1][1+i];
		for ( int i = 0; i < 5; i++ )
			cin >> F[2][i];
		for ( int i = 0; i < 3; i++ )
			cin >> F[3][1+i];
		cin >> F[4][2];

		// óðT·
		int empty_count = 0;
		for ( int i = 0; i < 5; i++ )
		{
			for ( int j = 0; j < 5; j++ )
			{
				if ( F[i][j] == 0 )
				{
					empty_x[empty_count] = j;
					empty_y[empty_count] = i;
					empty_count++;
				}
			}
		}

		// ½[»[³DæTõ
		V.insert( F );
		now = 0;
		bool goal_flag = false;
		for ( int i = 0; i < 20; i++ )
		{
			if ( search( i ) )
			{
				goal_flag = true;
				break;
			}
		}

		if ( goal_flag )
			cout << now << endl;
		else
			cout << "NA" << endl;

	}
	return 0;
}