require 'set'
loop do
    n = gets.to_i
    break if n == 0
    wall = (1..2).map { gets.split.map(&:to_i) }
    queue = [[0, 1], [1, 1]]
    reached = Set[*queue]
    jump = 1
    ans = nil
    until queue.empty?
        new_queue = []
        until queue.empty?
            w, h0 = queue.shift
            if h0 >= n - 2
                ans = jump
                break
            end
            w = 1 - w
            h = h0 + 2
            if wall[w][h] == 2
                h -= 1 until h == 0 || wall[w][h] != 2
            elsif wall[w][h] == 1
                h += 1 while h < n - 1 && wall[h+1] == 1
                if h == n - 1
                    ans = jump
                    break
                end
            end
            if !reached.include?([w, h])
                reached << [w, h]
                new_queue << [w, h]
            end
            h = h0 + 1
            if wall[w][h] == 2
                h -= 1 until h == 0 || wall[w][h] != 2
            elsif wall[w][h] == 1
                h += 1 while h < n - 1 && wall[h+1] == 1
                if h == n - 1
                    ans = jump
                    break
                end
            end
            if !reached.include?([w, h])
                reached << [w, h]
                new_queue << [w, h]
            end
        end
        break if ans
        jump += 1
        queue = new_queue
    end
    puts ans ? ans : 'NA'
end

