// 2011/07/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int wal[2][100];
		for(int i=0; i<n; i++)
			cin >> wal[0][i];
		wal[0][n] = 0;
		for(int i=0; i<n; i++)
			cin >> wal[1][i];
		wal[1][n] = 0;

		int cnt0 = 0;
		int bld = 0;
		int flr = 0;
		int memo[2];
		memo[0] = memo[1] = 0;
		while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
			flr++;

		while(true){
			// cout << bld << ' ' << flr << endl;
			if(flr>=n-1)
				break;

			bld = (bld+1)%2;
			flr = flr+2;

			while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
				flr++;

			while(wal[bld][flr]==2)
				flr--;

			if(memo[bld]>=flr){
				cnt0 = 300;
				break;
			}
			else
				memo[bld] = flr;

			cnt0++;
		}

		int cnt1 = 0;
		bld = 1;
		flr = 0;
		memo[0] = memo[1] = 0;
		while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
			flr++;

		while(true){
			// cout << bld << ' ' << flr << endl;
			if(flr>=n-1)
				break;

			bld = (bld+1)%2;
			flr = flr+2;

			while(wal[bld][flr]==1&&wal[bld][flr+1]==1)
				flr++;

			while(wal[bld][flr]==2)
				flr--;

			if(memo[bld]>=flr){
				cnt1 = 300;
				break;
			}
			else
				memo[bld] = flr;

			cnt1++;
		}

		if(cnt0==300&&cnt1==300)
			cout << "NA" << endl;
		else if(cnt0<cnt1)
			cout << cnt0 << endl;
		else
			cout << cnt1 << endl;
	}

	return 0;
}