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

