n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

x = a[0]
for i in range(1,n):
    x = x^a[i]


a.append(x)

a_=[]
b_=[]
for i in range(n):
    if a[i]!=b[i]:
        a_.append(a[i])
        b_.append(b[i])

a_.sort()
b_.sort()

boo = False
for i in range(len(a_)):
    if a_[i]!=b_[i]:
        if boo == False:
            boo =True
        else:
            print('-1')
            return
print(len(b_))