#include <bits/stdc++.h>
using namespace std;

const int inf = 1e8;

int building[2][1000];
bool visited[2][1000];
int n;
int solve(int t){
    memset(visited, false, sizeof(visited));
    queue<pair<pair<int, int>, int> > q;
    q.push(make_pair(make_pair(t, 0), 0));
    while(!q.empty()){
        pair<pair<int, int>, int> p = q.front(); q.pop();
        int x = p.first.first, y = p.first.second, count = p.second;
        if(visited[x][y]) continue;
        visited[x][y] = true;

        if(building[x][y] == 2) while(building[x][y] == 2) y--;
        if(building[x][y] == 1) while(building[x][y] == 1 && building[x][y+1] == 1) y++;

        if(y == n-1) return count;
        for(int i=0; i < 3; i++){
            if(y+i < n) q.push(make_pair(make_pair(!x, y+i), count+1));
        }
    }
    return inf;
}

int main(){
    while(cin >> n, n){
        memset(building, 0, sizeof(building));
        for(int i=0; i< 2; i++) for(int j=0; j < n; j++) cin >> building[i][j];
        int ret = min(inf, min(solve(0), solve(1)));
        if(ret == inf) cout << "NA" << endl;
        else cout << ret << endl;
    }
    return 0;
}