n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

cnt = 0
while b != a
  cnt += 1
  t = b.index(b.max)
  b[t] -= (b[t-1] + b[t+1-b.length])
  if b[t] < a[t]
    puts "-1"
    exit
  end
end
puts cnt
