def climb (h, a_b, c, n)
  return c if h > n-1 && $towers[a_b][h] != 2
  return nil if $visited[a_b][h].nil?
  $visited[a_b][h] = nil
  case $towers[a_b][h]
  when 1
    h += 1 while $towers[a_b][h] == 1
    h -= 1
  when 2
    h -= 1 while $towers[a_b][h] == 2
  end
  climb(h+2, (a_b.zero? ? 1 : 0), c+1, n)
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]
  $visited = [Array.new(n, true), Array.new(n, true)]
  count_a = climb(0, 0, 0, n)
  $visited = [Array.new(n, true), Array.new(n, true)]
  count_b = climb(0, 1, 0, n)
  if !count_a && !count_b
    puts "NA"
  elsif !count_a
    puts count_b
  elsif !count_b
    puts count_a
  else
    puts ((count_a < count_b) ? count_a : count_b)
  end
end