#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

		int a[2][200];
		memset(a,0,sizeof(a));
		for (int i = 0;i < 2;i++){
			for (int j = 0;j < n;j++){
				cin >> a[i][j];
			}
		}

		int b[2][200];
		memset(b,0,sizeof(b));
		for (int i = 0;i < 2;i++){
			for (int j = 0;j < n;j++){
				if(a[i][j] == 1 && a[i][j+1] != 1){
					for (int k = j;;k--){
						if(a[i][k] != 1) break;
						b[i][k] = j;
					}
				}
				if(a[i][j] != 2 && a[i][j+1] == 2){
					for (int k = j+1;;k++){
						if(a[i][k] != 2) break;
						b[i][k] = j;
					}
				}
			}
		}

		int d[2][200];
		memset(d,-1,sizeof(d));
		d[0][b[0][0]] = 0; d[1][b[1][0]] = 0;
		queue<P> que;
		que.push(P(0,b[0][0])); que.push(P(1,b[1][0]));
		while(que.size()){
			P p = que.front(); que.pop();
			if(p.second >= n-1) break;
			int nex = 1;
			if(p.first == 1) nex = 0;
			for (int i = 0;i < 3;i++){
				P t = P(nex,p.second+i);
				if(b[t.first][t.second] != 0){
					t = P(t.first,b[t.first][t.second]);
				}
				if(d[t.first][t.second] == -1){
					que.push(t);
					d[t.first][t.second] = d[p.first][p.second] + 1;
				}
			}
		}

		int ans =  min(d[1][n-1],d[0][n-1]);
		if(ans == -1) ans =  max(d[0][n-1],d[1][n-1]);
		if(ans == -1) cout << "NA" << endl;
		else cout << ans << endl;

	}

	return 0;

}

