N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
count =0
while B != A: 
    if max(B) < max(A):
        count =-1
        break
    i = B.index(max(B))
    if i+1 >= N:
        B[i] = B[i] - B[0] - B[i-1]
    else:
        B[i] = B[i] - B[i+1] - B[i-1]
    count += 1
    
print(count)