#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;     // building, height, jump
static const int INF = 1e8;
int A[2][103];
bool visited[2][103];
int n;

int check(queue<PP> que)
{
	while (!que.empty())
	{
		PP pp = que.front();
		que.pop();
		if (A[pp.first.first][pp.first.second] == 1)
		{
			while (A[pp.first.first][pp.first.second] == 1)
			{
				++pp.first.second;
			}
			--pp.first.second;
			
		}
		else if (A[pp.first.first][pp.first.second] == 2)
		{
			while (A[pp.first.first][pp.first.second] == 2)
			{
				--pp.first.second;
			}
		}
		if (visited[pp.first.first][pp.first.second])
		{
			continue;
		}
		visited[pp.first.first][pp.first.second] = true;
		if (pp.first.second == n - 1)
		{
			return(pp.second);
		}
		int building = (pp.first.first + 1) % 2;
		for (int i = 0; i < 3; ++i)
		{
			que.push(PP(P(building, pp.first.second + i), pp.second + 1));
		}
	}
	return(INF);
}

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> n, n)
	{
		memset(A, 0, sizeof(A));
		for (int i = 0; i < 2; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				cin >> A[i][j];
			}
		}
		int minJump = INF;
		memset(visited, 0, sizeof(visited));
		queue<PP> que;
		que.push(PP(P(0, 0), 0));
		que.push(PP(P(1, 0), 0));
		minJump = min(minJump, check(que));
		if (minJump == INF)
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << minJump << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}