import sys
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a == b:
	print(0)
	sys.exit()
if sorted(a) == sorted(b):
	res = 0
	for i in range(n):
		if a[i] != b[i]:
			res += 1
	print(res+1)
	sys.exit()
x = 0
for i in range(n):
	x ^= a[i]
#sa, sb = sorted(a), sorted(b)
ca, cb = Counter(a), Counter(b)
a_only, b_only = 0, 0
for k in ca.keys():
	if ca[k] > cb[k]:
		a_only += ca[k] - cb[k]
		only_a = k
for k in cb.keys():
	if cb[k] > ca[k]:
		b_only += cb[k] - ca[k]
		only_b = k

if a_only != 1 or b_only != 1:
	print(-1)
	sys.exit()
plus = False
res = 0
for i in range(n):
	if a[i] != b[i]:
		res += 1
		if a[i] == only_a and b[i] == only_b and cb[only_a] == 0:
			plus = True
print(res + plus)