#include <iostream>
#include <algorithm>
using namespace std;

int data[2][100];
int n;

void solve() {
  int ans = -1;
  for(int i = 0; i < 2; i++) {
    bool visited[2][100];
    int jump, nb, nf;
    jump = 0;
    nb = i;
    nf = 0;
    if(data[nb][nf] == 1) {
      while(nf < n && data[nb][nf] == 1) nf++;
      nf--;
    }

    fill_n(visited[0], 2*100, false);
    visited[i][0] = true;
    while(1) {
      if(nf == n-1) {
	if(ans == -1 || jump < ans) {
	  ans = jump;
	}
	break;
      }
      jump++;
      nb = 1 - nb;
      nf += 2;
      if(nf >= n) nf--;
      if(data[nb][nf] == 1) {
	while(nf < n && data[nb][nf] == 1) nf++;
	nf--;
      } else if(data[nb][nf] == 2) {
	while(data[nb][nf] == 2) nf--;
      }
      if(visited[nb][nf]) break;
      visited[nb][nf] = true;
    }
  }
  if(ans == -1) cout << "NA" << endl;
  else          cout << ans << endl;
}

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

    for(int i = 0; i < 2; i++) {
      for(int j = 0; j < n; j++) {
	cin >> data[i][j];
      }
    }
    solve();
  }
  return 0;
}