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

const int INF = 111111111;
typedef pair<int,int> P;

int b[2][150];
int n;
int d[2][150];
int v[3] = {0, 1, 2};

int bfs(){
  queue<P> que;
  for(int i = 0;i < 2; i++)
    for(int j = 0;j < 150; j ++) d[i][j] = INF;

  if(b[0][0] == 1){
    int i;
    for(i = 0;b[0][i] == 1 && i < n; i++) ;
    que.push(P(0,i-1));
    d[0][i-1] = 0;
  }
  else{
    que.push(P(0,0));
    d[0][0] = 0;
  }
  if(b[1][0] == 1){
    int i;
    for(i = 0;b[1][i] == 1 && i < n; i++) ;
    que.push(P(1,i-1));
    d[1][i-1] = 0;
  }
  else{
    que.push(P(1,0));
    d[1][0] = 0;
  }

  while(que.size()){
    P p = que.front(); que.pop();
    if(p.second >= n-1 && b[p.first][p.second] != 2) return d[p.first][p.second];

    for(int i = 0;i < 3; i++){
      int nx = (p.first + 1) % 2, ny = p.second + v[i];

      if(b[nx][ny] == 2){
	int i;
	for(i = ny;b[nx][i] == 2 && i >= 0; i--) ;
	ny = i;
      }
      else if(b[nx][ny] == 1){
	int i;
	for(i = ny;b[nx][i] == 1 && i < n; i++) ;
	ny = i - 1;
      }
      if(ny < n && d[nx][ny] == INF){
	que.push(P(nx,ny));
	d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return -1;
}

int main(void){
  for( ; ; ){
    cin >> n;
    if(!n) break;
    for(int i = 0;i < n; i++) cin >> b[0][i];
    for(int i = 0;i < n; i++) cin >> b[1][i];

    int res = bfs();

    if(res == -1) cout << "NA" << endl;
    else cout << res << endl;
  }
}
