def push_stack(h, a_b, c)
  $stack.push [h, a_b, c+1]
  $stack.push [h+1, a_b, c+1]
  $stack.push [h+2, a_b, c+1]
end

while n = gets.to_i
  break if n.zero?
  towerA = gets.split.map(&:to_i)
  towerB = gets.split.map(&:to_i)
  towers = [towerA, towerB]
  $stack = [[0, 0, 0], [0, 1, 0]] #[0]height [1]A or B [2]count
  loop do
    current_wall = $stack.pop
    height = current_wall[0]
    a_b = current_wall[1]
    opposite = (a_b.zero? ? 1 : 0)
    count = current_wall[2]
    if count > 200
      puts "NA"
      break
    end
    if height == n-1 && towers[a_b][height] != 2
      puts count
      break
    else
      case towers[a_b][height]
      when 0
        push_stack(height, opposite, count)
      when 1
        height += 1 while towers[a_b][height] == 1
        height -= 1
        push_stack(height, opposite, count)
      when 2
        height -= 1 while towers[a_b][height] == 2
        push_stack(height, opposite, count)
      end
    end
  end
end