#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

class P{
public:
	int b,h,cost; //rÌÇÁ¿É¢é©,rÌK,Wvñ

	P(int _b,int _h,int _cost){
		b = _b;
		h = _h;
		cost = _cost;
	}
};

int n;
int b[2][101];
bool closed[2][101];

int solve(void){
	queue<P> q;
	memset(closed,0,sizeof(closed));
	q.push(P(0,0,0));
	q.push(P(1,0,0));

	while(!q.empty()){
		P p = q.front(); q.pop();
		if(b[p.b][p.h] == 1){ //Íµ²
			while(p.h<n && b[p.b][p.h]==1) p.h++;
			p.h--;
		}
		else if(b[p.b][p.h] == 2){ //·×éÇ
			while(b[p.b][p.h]==2) p.h--;
		}

		if(closed[p.b][p.h]) continue;
		closed[p.b][p.h] = true;

		if(p.h == n-1) return p.cost;

		rep(i,3) if(n > p.h + i) {
			q.push(P(!p.b,p.h+i,p.cost+1));
		}
	}

	return -1;
}

int main(void){
	while(cin>>n,n){
		rep(i,2) rep(j,n) cin>>b[i][j];

		int cal = solve();
		if(cal == -1) cout<<"NA\n";
		else cout<<cal<<endl;
	}

	return 0;
}