#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector< vector<int> > w(n, vector<int>(2));
		for (int i = 0; i < n; i++) {
			cin >> w[i][0];
		}
		for (int i = 0; i < n; i++) {
			cin >> w[i][1];
		}
		vector< vector<int> > dp1(n, vector<int>(2, 500));
		dp1[0][0] = 0;
		queue<Q> q;
		int k = 0;
		while (k < n-1 && w[k][0] == 1 && w[k+1][0] == 1) {
			k++;
		}
		dp1[k][0] = 0;
		q.push(Q(1, P(k, 1)));
		k++;
		if (k < n) {
			q.push(Q(1, P(k, 1)));
			k++;
			if (k < n) {
				q.push(Q(1, P(k, 1)));
			}
		}
		while (!q.empty()) {
			Q qq = q.front();
			q.pop();
			P p = qq.second;
			if (dp1[p.first][qq.first] <= p.second) {
			} else {
				dp1[p.first][qq.first] = p.second;
				if (w[p.first][qq.first] == 2) {
					dp1[p.first][qq.first] = 500;
				}
				while (w[p.first][qq.first] == 2) {
					p.first--;
				}
				while (p.first < n-1 && w[p.first][qq.first] == 1 && w[p.first+1][qq.first] == 1) {
					p.first++;
				}
				if (dp1[p.first][qq.first] < p.second) {
				} else {
					dp1[p.first][qq.first] = p.second;
					q.push(Q(1-qq.first, P(p.first, p.second+1)));
					p.first++;
					if (p.first < n) {
						q.push(Q(1-qq.first, P(p.first, p.second+1)));
						p.first++;
						if (p.first < n) {
							q.push(Q(1-qq.first, P(p.first, p.second+1)));
						}
					}
				}
			}
		}
		/*for (int i = 0; i < n; i++) {
			cout << dp1[i][0] << ' ';
		}
		cout << endl;
		for (int i = 0; i < n; i++) {
			cout << dp1[i][1] << ' ';
		}
		cout << endl;*/
		vector< vector<int> > dp2(n, vector<int>(2, 500));
		dp2[0][1] = 0;
		k = 0;
		while (k < n-1 && w[k][1] == 1 && w[k+1][1] == 1) {
			k++;
		}
		dp2[k][1] = 0;
		q.push(Q(0, P(k, 1)));
		k++;
		if (k < n) {
			q.push(Q(0, P(k, 1)));
			k++;
			if (k < n) {
				q.push(Q(0, P(k, 1)));
			}
		}
		while (!q.empty()) {
			Q qq = q.front();
			q.pop();
			P p = qq.second;
			if (dp2[p.first][qq.first] <= p.second) {
			} else {
				dp2[p.first][qq.first] = p.second;
				if (w[p.first][qq.first] == 2) {
					dp2[p.first][qq.first] = 500;
				}
				while (w[p.first][qq.first] == 2) {
					p.first--;
				}
				while (p.first < n-1 && w[p.first][qq.first] == 1 && w[p.first+1][qq.first] == 1) {
					p.first++;
				}
				if (dp2[p.first][qq.first] < p.second) {
				} else {
					dp2[p.first][qq.first] = p.second;
					q.push(Q(1-qq.first, P(p.first, p.second+1)));
					p.first++;
					if (p.first < n) {
						q.push(Q(1-qq.first, P(p.first, p.second+1)));
						p.first++;
						if (p.first < n) {
							q.push(Q(1-qq.first, P(p.first, p.second+1)));
						}
					}
				}
			}
		}
		/*for (int i = 0; i < n; i++) {
			cout << dp2[i][0] << ' ';
		}
		cout << endl;
		for (int i = 0; i < n; i++) {
			cout << dp2[i][1] << ' ';
		}
		cout << endl;*/
		int cc = min(dp1[n-1][0], min(dp1[n-1][1], min(dp2[n-1][0], dp2[n-1][1])));
		if (cc == 500) {
			cout << "NA" << endl;
		} else {
			cout << cc << endl;
		}
	}
	return 0;
}