In Berland each high school student is characterized by academic performance — integer value between 1 and 5.

In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.

The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.

To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.

Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.


-----Input-----

The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.

The second line contains sequence of integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 5), where a_{i} is academic performance of the i-th student of the group A.

The third line contains sequence of integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 5), where b_{i} is academic performance of the i-th student of the group B.


-----Output-----

Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.


-----Examples-----
Input
4
5 4 4 4
5 5 4 5

Output
1

Input
6
1 1 1 1 1 1
5 5 5 5 5 5

Output
3

Input
1
5
3

Output
-1

Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1

Output
4

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Constructive algorithms


Solutions:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
swaps = 0
for i in range(1, 6):
	a_count = a.count(i)
	b_count = b.count(i)
	diff = abs(a_count - b_count)
	if diff % 2 != 0:
		swaps = -2
		break
	swaps += diff // 2
print(swaps // 2)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = {}
	d = {}
	for i in range(n):
		if a[i] in c:
			c[a[i]] += 1
		else:
			c[a[i]] = 1
	for i in range(n):
		if b[i] in d:
			d[b[i]] += 1
		else:
			d[b[i]] = 1
	e = 0
	g = 0
	h = 0
	m = 0
	o = 0
	for i in c:
		if i in d:
			if c[i] == d[i]:
				continue
			else:
				if c[i] > d[i]:
					g = abs(c[i] - d[i])
				else:
					g = 0
				if g % 2 == 0:
					h += g // 2
				else:
					h = -1
					break
		else:
			g = c[i]
			if g % 2 == 0:
				e += g // 2
			else:
				e = -1
				break
	for i in d:
		if i not in c:
			g = d[i]
			if g % 2 == 0:
				o += g // 2
			else:
				o = -1
	if h == -1 or e == -1 or o == -1:
		e = -1
	else:
		e = h + e
	print(e)
main()


n = int(input())
l_s1 = [0 for i in range(5)]
l_s2 = [0 for i in range(5)]
l_d = [0 for i in range(5)]
for i in list(map(int, input().split())):
	l_s1[i - 1] += 1
for i in list(map(int, input().split())):
	l_s2[i - 1] += 1
for i in range(5):
	l_d[i] = abs(l_s1[i] - l_s2[i])
	if l_d[i] % 2 == 1:
		print(-1)
		quit()
	else:
		l_d[i] //= 2
if sum(l_d) % 2 == 1:
	print(-1)
	quit()
else:
	print(sum(l_d) // 2)


n = int(input())
linea = list(map(int, input().split()))
lineb = list(map(int, input().split()))
lines = linea + lineb
c1 = lines.count(1)
c2 = lines.count(2)
c3 = lines.count(3)
c4 = lines.count(4)
c5 = lines.count(5)
cc1 = linea.count(1)
cc2 = linea.count(2)
cc3 = linea.count(3)
cc4 = linea.count(4)
cc5 = linea.count(5)
if c1 % 2 == 1 or c2 % 2 == 1 or c3 % 2 == 1 or (c4 % 2 == 1) or (c5 % 2 == 1):
	print(-1)
else:
	print(int(abs(c1 / 2 - cc1) + abs(c2 / 2 - cc2) + abs(c3 / 2 - cc3) + abs(c4 / 2 - cc4) + abs(c5 / 2 - cc5)) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0, 0, 0, 0, 0, 0]
t = False
for i in range(1, 6):
	c[i] += a.count(i) + b.count(i)
	if c[i] % 2:
		t = True
		break
if t:
	print(-1)
else:
	answer = 0
	(a1, b1) = (0, 0)
	for i in range(1, 6):
		a1 += abs(c[i] / 2 - a.count(i))
	print(int(a1 // 2))


n = int(input().strip())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
(fa, fb) = ([0] * 6, [0] * 6)
for i in range(n):
	fa[a[i]] += 1
	fb[b[i]] += 1
total = 0
for (i, j) in zip(fa, fb):
	if (i + j) % 2:
		exit(print(-1))
	total += abs(i - j) // 2
print(total // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = [0] * 6
b1 = [0] * 6
for i in a:
	a1[i] += 1
for i in b:
	b1[i] += 1
ans = 0
for i in range(1, 6):
	if (a1[i] + b1[i]) % 2 != 0:
		ans = -1
		break
	ans += (max(a1[i], b1[i]) - min(a1[i], b1[i])) // 2
if ans == -1:
	print(-1)
else:
	print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d1 = [0] * 6
d2 = [0] * 6
for i in range(n):
	d1[a[i]] += 1
	d2[b[i]] += 1
diff1 = 0
diff2 = 0
for i in range(6):
	if (d1[i] + d2[i]) % 2 != 0:
		print(-1)
		exit()
	if d1[i] - d2[i] > 0:
		diff1 += abs(d1[i] - d2[i])
	else:
		diff2 += abs(d1[i] - d2[i])
if diff1 == diff2 and diff1 % 2 == 0:
	print(diff1 // 2)
else:
	print(-1)


def f():
	n = int(input())
	a = [0] * 5
	b = [0] * 5
	X = [int(x) for x in input().split()]
	for x in X:
		a[x - 1] += 1
	X = [int(x) for x in input().split()]
	for x in X:
		b[x - 1] += 1
	for i in range(5):
		if (a[i] + b[i]) % 2 == 1:
			print('-1')
			return
	x = 0
	for i in range(5):
		x += abs(a[i] - b[i]) / 2
	print(int(x / 2))
f()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c1 = [0, 0, 0, 0, 0, 0, 0]
c2 = [0, 0, 0, 0, 0, 0, 0]
for i in a:
	c1[i] += 1
for i in b:
	c2[i] += 1
for i in range(6):
	if (c1[i] + c2[i]) % 2 == 1:
		print(-1)
		break
else:
	ans = 0
	for i in range(6):
		ans += abs(c1[i] - c2[i])
	print(ans // 4)


import sys
inf = float('inf')
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
A = get_array()
B = get_array()
mydict_A = dict()
mydict_B = dict()
for (i, j) in zip(A, B):
	mydict_A[i] = mydict_A.get(i, 0) + 1
	mydict_B[j] = mydict_B.get(j, 0) + 1
score = [0] * 6
for (i, j) in zip(A, B):
	score[i] += 1
	score[j] += 1
flag = 0
for i in range(1, 6):
	if score[i] & 1:
		flag = 1
		break
if flag == 1:
	print(-1)
	exit(0)
contri_A = 0
contri_B = 0
for i in mydict_A:
	contri_A += max(mydict_A[i] - score[i] / 2, 0)
for i in mydict_B:
	contri_B += max(mydict_B[i] - score[i] / 2, 0)
if contri_A != contri_B:
	print(-1)
	exit(0)
print(int(contri_A))


import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
special = 0
lcng = rcng = 0
for j in range(1, 6):
	l = a.count(j)
	r = b.count(j)
	if l != r:
		if l == 1 and r == 0 or (r == 1 and l == 0) or (l + r) % 2 != 0:
			special = 1
		elif l > r and special != 1:
			lcng += int(l - (l + r) / 2)
		else:
			rcng += int(r - (l + r) / 2)
if lcng != rcng or special == 1:
	print('-1')
else:
	print(lcng)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(d1, d2) = ({1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, {1: 0, 2: 0, 3: 0, 4: 0, 5: 0})
for i in range(n):
	d1[a[i]] += 1
	d2[b[i]] += 1
(a, b, f) = (0, 0, 0)
for i in range(1, 6):
	if d1[i] >= d2[i]:
		w = d1[i] + d2[i]
		if w & 1:
			f = 1
			break
		else:
			a += d1[i] - w // 2
	else:
		w = d1[i] + d2[i]
		if w & 1:
			f = 1
			break
		else:
			b += d2[i] - w // 2
if f == 0 and a == b:
	print(a)
else:
	print(-1)


n = int(input())
a = input()
b = input()
q = (a + b).count('1')
w = (a + b).count('2')
e = (a + b).count('3')
r = (a + b).count('4')
t = (a + b).count('5')
y = a.count('1')
u = a.count('2')
o = a.count('3')
p = a.count('4')
s = a.count('5')
if any([x % 2 != 0 for x in [q, w, e, r, t]]):
	print(-1)
else:
	print(int((abs(int(q / 2) - y) + abs(int(w / 2) - u) + abs(int(e / 2) - o) + abs(int(r / 2) - p) + abs(int(t / 2) - s)) / 2))


n = int(input())
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))

def count(a, listt):
	l = 0
	for i in range(0, len(listt)):
		if a == listt[i]:
			l += 1
	return l
x = True
l = 0
for i in range(1, 6):
	if (count(i, c1) + count(i, c2)) % 2 == 0:
		l += abs(count(i, c1) - count(i, c2))
	else:
		print(-1)
		x = False
		break
if x == True:
	print(l // 4)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
c = 0
for i in range(1, 6):
	x = a.count(i)
	y = b.count(i)
	if (x + y) % 2 == 0:
		s = s + abs(x - y) // 2
	else:
		c = 1
		break
if c == 1:
	print(-1)
else:
	print(s // 2)


import sys

def main():
	n = int(input())
	c1 = [0] * 6
	c2 = [0] * 6
	for i in input().split():
		c1[int(i)] += 1
	for i in input().split():
		c2[int(i)] += 1
	ans = 0
	for i in range(6):
		if (c1[i] + c2[i]) % 2 == 1:
			print(-1)
			return
		ans += abs((c1[i] + c2[i]) // 2 - c1[i])
	print(ans // 2)
_fin = sys.stdin
_fout = sys.stdout
if 'ANDREIKKAA' in sys.argv:
	_fin = open('input.txt', 'r')
	pass
else:
	pass
if _fin:
	sys.stdin = _fin
if _fout:
	sys._stdout = _fout
main()


n = int(input())
adata = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
bdata = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
a = list(map(int, input().split()))
for x in a:
	adata[x] = adata[x] + 1
b = list(map(int, input().split()))
for x in b:
	bdata[x] = bdata[x] + 1
ans = 0
ans = ans + abs(adata[1] - bdata[1])
ans = ans + abs(adata[2] - bdata[2])
ans = ans + abs(adata[3] - bdata[3])
ans = ans + abs(adata[4] - bdata[4])
ans = ans + abs(adata[5] - bdata[5])
if (adata[1] + bdata[1]) % 2 != 0 or (adata[1] + bdata[1]) % 2 != 0 or (adata[2] + bdata[2]) % 2 != 0 or ((adata[3] + bdata[3]) % 2 != 0) or ((adata[4] + bdata[4]) % 2 != 0) or ((adata[5] + bdata[5]) % 2 != 0):
	ans = -1
print(ans // 4)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnta = [0 for i in range(0, 6)]
cntb = [0 for i in range(0, 6)]
for i in range(0, n):
	cnta[a[i]] += 1
	cntb[b[i]] += 1
flag = 0
for i in range(1, 6):
	if (cnta[i] + cntb[i]) % 2 == 1:
		flag = 1
if flag:
	print('-1')
else:
	ans = 0
	for i in range(1, 6):
		val = (cnta[i] + cntb[i]) / 2
		if cnta[i] > val:
			ans += cnta[i] - val
	print(int(ans))


import sys
n = int(input())
g1 = list(map(int, input().split()))
g2 = list(map(int, input().split()))
ans = 0
for i in range(1, 6):
	n1 = g1.count(i)
	n2 = g2.count(i)
	if abs(n1 - n2) % 2 != 0:
		print(-1)
		sys.exit()
	ans += abs(n1 - n2) // 2
print(ans // 2)


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def Solution(arr1, arr2, n):
	cnt = [0 for _ in range(6)]
	for v in arr1:
		cnt[v] += 1
	for u in arr2:
		cnt[u] -= 1
	ans = 0
	for c in cnt:
		if c % 2 != 0:
			print(-1)
			return
		else:
			ans += abs(c)
	print(ans // 4)

def main():
	n = int(input())
	arr1 = get_ints_in_list()
	arr2 = get_ints_in_list()
	Solution(arr1, arr2, n)
main()


n = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
c = [0] * 8
ans = 0
for i in l:
	c[i] += 1
for i in l1:
	c[i] -= 1
for i in range(6):
	if c[i] % 2:
		print(-1)
		break
	ans += abs(c[i]) // 2
else:
	print(ans // 2)


n = int(input())
a = list(sorted(map(int, input().split())))
b = list(sorted(map(int, input().split())))
s = []
ei = 0
for i in range(5):
	t = [a.count(i + 1), b.count(i + 1)]
	s.append(t[0] - t[1])
	if sum(t) % 2 == 1:
		ei = 1
if bool(ei):
	print(-1)
else:
	print(int(sum(filter(lambda x: x > 0, s)) / 2))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
countsofa = [0 for i in range(5)]
countsofb = [0 for i in range(5)]
totalcount = [0 for i in range(5)]
for i in range(len(a)):
	countsofa[a[i] - 1] += 1
for i in range(len(b)):
	countsofb[b[i] - 1] += 1
for i in range(len(countsofa)):
	totalcount[i] = countsofa[i] + countsofb[i]
temp = 1
for i in range(len(totalcount)):
	if totalcount[i] % 2 != 0:
		temp = 0
		break
if temp == 0:
	print('-1')
else:
	ans = 0
	for i in range(len(countsofa)):
		if countsofa[i] >= countsofb[i]:
			ans = ans + totalcount[i] / 2 - countsofb[i]
		else:
			ans = ans + totalcount[i] / 2 - countsofa[i]
	print(int(ans / 2))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0 for i in range(5)]
bb = [0 for i in range(5)]
cc = [0 for i in range(5)]
for i in range(n):
	aa[a[i] - 1] += 1
	cc[a[i] - 1] += 1
for i in range(n):
	bb[b[i] - 1] += 1
	cc[b[i] - 1] += 1
f = True
for i in range(5):
	if cc[i] % 2 != 0:
		f = False
		break
	else:
		cc[i] //= 2
if not f:
	print(-1)
else:
	o = 0
	for i in range(5):
		o += abs(cc[i] - aa[i])
	print(o // 2)


ans = 0
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = {i: 0 for i in range(1, 6)}
y = {i: 0 for i in range(1, 6)}
for i in a:
	x[i] += 1
for i in b:
	y[i] += 1
ans = [0] * 2
for i in range(1, 6):
	tmp = x[i] - y[i]
	if tmp % 2 != 0:
		print(-1)
		exit()
	elif tmp > 0:
		ans[1] += tmp
	else:
		ans[0] += tmp
print(ans[1] // 2 if sum(ans) == 0 else -1)


input()
A = [0] * 5
B = [0] * 5
L1 = list(map(int, input().split()))
L2 = list(map(int, input().split()))
for a in L1:
	A[a - 1] += 1
for b in L2:
	B[b - 1] += 1
toA = 0
f = True
for i in range(5):
	if (A[i] + B[i]) % 2 == 1:
		f = False
		break
	elif B[i] > A[i]:
		toA += B[i] - (A[i] + B[i]) // 2
if not f:
	print(-1)
else:
	print(toA)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = [0] * 5
	balance = [0] * 5
	for e in a:
		count[e - 1] += 1
		balance[e - 1] += 1
	for e in b:
		count[e - 1] += 1
		balance[e - 1] -= 1
	for e in count:
		if e % 2 != 0:
			print(-1)
			return
	print(sum([abs(i) for i in balance]) // 4)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
a_dict = {i: 0 for i in range(1, 6)}
b_dict = {i: 0 for i in range(1, 6)}
for s in a:
	if s in a_dict:
		a_dict[s] += 1
	else:
		a_dict[s] = 1
for t in b:
	if t in b_dict:
		b_dict[t] += 1
	else:
		b_dict[t] = 1
ans = 0
for i in range(1, 6):
	if (a_dict[i] + b_dict[i]) % 2 == 1:
		ans = -2
		break
	else:
		ans += abs((a_dict[i] + b_dict[i]) // 2 - a_dict[i])
ans = ans // 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
for x in a:
	d[x] = d.get(x, 0) + 1
for x in b:
	d[x] = d.get(x, 0) - 1
ans = 0
cnt = 0
for (k, v) in d.items():
	ans += abs(v)
	cnt += v % 2
if cnt > 0:
	print(-1)
else:
	print(ans // 4)


n = int(input())
x = [int(q) for q in input().split()]
y = [int(w) for w in input().split()]
o = x.count(1)
t = x.count(2)
th = x.count(3)
f = x.count(4)
fi = x.count(5)
o1 = y.count(1)
t1 = y.count(2)
th1 = y.count(3)
f1 = y.count(4)
fi1 = y.count(5)
if abs(o - o1) % 2 != 0 or abs(t - t1) % 2 != 0 or abs(th - th1) % 2 != 0 or (abs(f - f1) % 2 != 0) or (abs(fi - fi1) % 2 != 0):
	print(-1)
elif (abs(o - o1) + abs(t - t1) + abs(th - th1) + abs(f - f1) + abs(fi - fi1)) % 2 != 0:
	print(-1)
else:
	ans = abs(o - o1) + abs(t - t1) + abs(th - th1) + abs(f - f1) + abs(fi - fi1)
	print(ans // 4)


n = int(input())
c1 = list(map(int, input().split(' ')))
c2 = list(map(int, input().split(' ')))
m1_add = []
m1_rem = []
m2_add = []
m2_rem = []
boolean = True
for i in range(1, 6):
	k1 = c1.count(i)
	k2 = c2.count(i)
	if abs(k1 - k2) % 2 == 1:
		print(-1)
		boolean = False
		break
	if k1 > k2:
		m1_rem.append((k1 - k2) // 2)
		m2_rem.append(0)
		m1_add.append(0)
		m2_add.append((k1 - k2) // 2)
	else:
		m1_rem.append(0)
		m2_rem.append((k2 - k1) // 2)
		m1_add.append((k2 - k1) // 2)
		m2_add.append(0)
if boolean:
	for i in range(5):
		for j in range(m1_add[i]):
			c1.append(i + 1)
		for j in range(m2_add[i]):
			c2.append(i + 1)
		for j in range(m1_rem[i]):
			c1.remove(i + 1)
		for j in range(m2_rem[i]):
			c2.remove(i + 1)
	if sum([int(i) for i in c1]) == sum([int(i) for i in c2]):
		print(sum(m1_add))
	else:
		print(-1)


l = [0] * 5
q = [0] * 5
G = 0
w = []
n = int(input())
p = input().rstrip().split(' ')
r = input().rstrip().split(' ')
for i in range(0, len(p)):
	l[int(p[i]) - 1] += 1
for i in range(0, len(r)):
	q[int(r[i]) - 1] += 1
S = []
for i in range(0, len(l)):
	if (l[i] + q[i]) % 2 != 0:
		G = 1
		break
	else:
		S.append((l[i] + q[i]) // 2)
if G == 1:
	print(-1)
else:
	D = 0
	for i in range(0, len(l)):
		if l[i] != q[i]:
			if l[i] > q[i]:
				g = S[i] - q[i]
				l[i] -= g
				q[i] += g
				w.append(g)
			else:
				g = S[i] - l[i]
				q[i] = q[i] - g
				l[i] += g
				w.append(g)
	for i in range(0, len(w)):
		D += w[i]
	print(D // 2)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
s1 = [0 for x in range(6)]
for i in l1:
	s1[i] += 1
s2 = [0 for x in range(6)]
for i in l2:
	s2[i] += 1
tot = 0
for i in range(1, 6):
	if (s1[i] + s2[i]) % 2 != 0:
		print(-1)
		exit(0)
for i in range(1, 6):
	tot += abs(s1[i] - s2[i])
print(tot // 4)


read = lambda : map(int, input().split())
n = int(input())
a = sorted(read())
b = sorted(read())
for i in range(1, 6):
	if (a.count(i) + b.count(i)) % 2:
		print(-1)
		exit()
cnt = 0
while 1:
	flag = False
	for i in range(n):
		if a.count(a[i]) > b.count(a[i]):
			for j in range(n):
				if a.count(b[j]) < b.count(b[j]) and a[i] != b[j]:
					(a[i], b[j]) = (b[j], a[i])
					cnt += 1
					break
			if flag:
				break
	if not flag:
		break
print(cnt)


n = int(input())
a = [0, 0, 0, 0, 0]
(*q,) = map(int, input().split())
(*w,) = map(int, input().split())
for i in range(5):
	a[i] = q.count(i + 1)
	a[i] -= w.count(i + 1)
	if a[i] % 2:
		print(-1)
		break
else:
	print(sum([abs(i // 2) for i in a]) // 2)


import math, sys

def main():
	n = int(input())
	a = map(int, input().split())
	b = map(int, input().split())
	a5 = 0
	a4 = 0
	a3 = 0
	a2 = 0
	a1 = 0
	b5 = 0
	b4 = 0
	b3 = 0
	b2 = 0
	b1 = 0
	ans = 0
	for i in a:
		if i == 5:
			a5 += 1
		if i == 4:
			a4 += 1
		if i == 3:
			a3 += 1
		if i == 2:
			a2 += 1
		if i == 1:
			a1 += 1
	for i in b:
		if i == 5:
			b5 += 1
		if i == 4:
			b4 += 1
		if i == 3:
			b3 += 1
		if i == 2:
			b2 += 1
		if i == 1:
			b1 += 1
	if (a5 + b5) % 2 == 0 and (a4 + b4) % 2 == 0 and ((a3 + b3) % 2 == 0) and ((a2 + b2) % 2 == 0) and ((a1 + b1) % 2 == 0):
		ans += max(a5, b5) - (a5 + b5) // 2
		ans += max(a4, b4) - (a4 + b4) // 2
		ans += max(a3, b3) - (a3 + b3) // 2
		ans += max(a2, b2) - (a2 + b2) // 2
		ans += max(a1, b1) - (a1 + b1) // 2
		print(ans // 2)
		sys.exit(0)
	print(-1)
main()


n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
(A, B) = ([0] * 6, [0] * 6)
for i in range(n):
	A[arr[i]] += 1
	B[brr[i]] += 1
tot = 0
(a, b) = (0, 0)
for i in range(6):
	if A[i] + B[i] & 1 == 1:
		print('-1')
		break
	if A[i] > B[i]:
		a += (A[i] - B[i]) // 2
	else:
		b += (B[i] - A[i]) // 2
else:
	if a == b:
		print(a)
	else:
		print(-1)


n = int(input())
a = [0 for x in range(6)]
b = a.copy()
for i in input().split(' '):
	a[int(i)] += 1
for i in input().split(' '):
	b[int(i)] += 1
flag = False
res = 0
for i in range(1, 6):
	temp = a[i] - b[i]
	if temp % 2:
		flag = True
		break
	if temp > 0:
		res += temp
print(-1) if flag == True else print(res // 2)


from collections import Counter as c
input()
a = c(map(int, input().split()))
b = c(map(int, input().split()))
d = c()
for i in range(1, 6):
	d[i] = abs(a[i] - b[i])
e = True
for i in range(1, 6):
	if d[i] % 2:
		e = False
		print(-1)
		break
if e:
	print(sum((d[i] for i in range(1, 6))) // 4)


from collections import Counter
n = int(input())
a = Counter(input().split())
b = Counter(input().split())
c = a + b
s = 0
for i in c:
	if c[i] % 2:
		print(-1)
		exit(0)
	else:
		s += abs(a[i] - b[i])
print(s // 4)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arra = [0] * 5
arrb = [0] * 5
ans = 0
for i in a:
	arra[i - 1] += 1
for i in b:
	arrb[i - 1] += 1
for i in range(5):
	if (arra[i] + arrb[i]) % 2:
		print(-1)
		exit()
for i in range(5):
	ans += abs(arra[i] - (arra[i] + arrb[i]) // 2)
print(ans // 2)


x = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = a + b
t = list(set(s))
k = 0
k1 = 0
flag = 0
d = {}
for i in range(len(t)):
	r = a.count(t[i])
	r1 = b.count(t[i])
	if (r - r1) % 2 == 1 or (r1 - r) % 2 == 1:
		print(-1)
		flag = 1
		break
	elif r > r1:
		k = k + r - r1
	else:
		k1 = k1 + r1 - r
if k % 2 == 0 and k == k1 and (flag == 0):
	print(k // 2)
elif flag == 0:
	print(-1)


import sys
n = int(input())
a_group = list(map(int, input().split()))
b_group = list(map(int, input().split()))
cnt_a = cnt_b = no = 0
for i in range(1, 6):
	c1 = a_group.count(i)
	c2 = b_group.count(i)
	if c1 == 1 and c1 > c2 or (c2 == 1 and c2 > c1):
		no = 1
	elif c1 > c2:
		cnt_a += c1 - int((c1 + c2) / 2)
	elif c1 < c2:
		cnt_b += c2 - int(c1 + c2) / 2
if no == 1 or cnt_a != cnt_b:
	print('-1')
else:
	print(cnt_a)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
a1 = a2 = b1 = b2 = c1 = c2 = d1 = d2 = e1 = e2 = 0
for i in range(len(l1)):
	if l1[i] == 1:
		a1 += 1
	elif l1[i] == 2:
		b1 += 1
	elif l1[i] == 3:
		c1 += 1
	elif l1[i] == 4:
		d1 += 1
	else:
		e1 += 1
	if l2[i] == 1:
		a2 += 1
	elif l2[i] == 2:
		b2 += 1
	elif l2[i] == 3:
		c2 += 1
	elif l2[i] == 4:
		d2 += 1
	else:
		e2 += 1
if (a1 + a2) % 2 != 0 or (b1 + b2) % 2 != 0 or (c1 + c2) % 2 != 0 or ((d1 + d2) % 2 != 0) or ((e1 + e2) % 2 != 0):
	print(-1)
else:
	m = 0
	if a1 > a2:
		m += a1 - a2
	if b1 > b2:
		m += b1 - b2
	if c1 > c2:
		m += c1 - c2
	if d1 > d2:
		m += d1 - d2
	if e1 > e2:
		m += e1 - e2
	print(m // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
for i in range(1, 6):
	(aCnt, bCnt) = (a.count(i), b.count(i))
	if (aCnt + bCnt) % 2:
		total = -2
		break
	else:
		total += abs(aCnt - bCnt) // 2
print(total // 2)


n = int(input())
first = tuple(map(int, input().split(' ')))
second = tuple(map(int, input().split(' ')))
answer = 0
for el in range(1, 6):
	if (first.count(el) + second.count(el)) % 2:
		answer = -1
if answer != -1:
	for el in range(1, 6):
		answer += abs(first.count(el) - (first.count(el) + second.count(el)) / 2)
	answer = int(answer / 2)
print(answer)


n = int(input())
lista = list(map(int, input().split()))
listb = list(map(int, input().split()))
coua = [0] * 6
coub = [0] * 6
for v in lista:
	coua[v] += 1
for v in listb:
	coub[v] += 1
ok = True
ans = 0
for v in range(1, 6):
	sumab = coua[v] + coub[v]
	if sumab % 2 != 0:
		ok = False
		break
	ans += abs(coua[v] - sumab // 2)
if not ok:
	print(-1)
else:
	print(ans // 2)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = [0] * 5
for elem in A:
	cnt[elem - 1] += 1
for elem in B:
	cnt[elem - 1] += 1
bad = 0
for elem in cnt:
	bad += elem % 2
if bad != 0:
	print(-1)
else:
	cntA = [0] * 5
	cntB = [0] * 5
	for elem in A:
		cntA[elem - 1] += 1
	for elem in B:
		cntB[elem - 1] += 1
	ans = 0
	for i in range(5):
		ans += abs(cntA[i] - cntB[i]) // 2
	print(ans // 2)


def pupils(n, lst1, lst2):
	count = 0
	(c, d) = ([0] * 6, [0] * 6)
	for i in range(n):
		c[lst1[i]] += 1
		d[lst1[i]] += 1
		c[lst2[i]] -= 1
		d[lst2[i]] -= 1
	for i in range(len(d)):
		if d[i] & 1:
			return -1
		count += abs(c[i])
	return count // 4
n = int(input())
a = [int(j) for j in input().split()]
b = [int(z) for z in input().split()]
print(pupils(n, a, b))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
d = 0
z = 0
for j in range(5):
	for i in range(n):
		if a[i] == j + 1:
			c += 1
	for i in range(n):
		if b[i] == j + 1:
			d += 1
	if (c + d) % 2 == 1:
		z = -2
		break
	else:
		z += abs(c - d) // 2
	d = 0
	c = 0
print(z // 2)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
totalcount = [0 for i in range(6)]
acount = [0 for i in range(6)]
bcount = [0 for i in range(6)]
for x in a:
	totalcount[x] += 1
	acount[x] += 1
for x in b:
	totalcount[x] += 1
	bcount[x] += 1
possible = True
for x in totalcount:
	if x % 2 == 1:
		possible = False
		break
countswitches = 0
for i in range(1, 6):
	if acount[i] > bcount[i]:
		countswitches += abs(acount[i] - bcount[i]) // 2
if possible:
	print(countswitches)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = {}
for x in a:
	cnt[x] = cnt.get(x, 0) + 1
for x in b:
	cnt[x] = cnt.get(x, 0) - 1
if any([abs(v) % 2 == 1 for v in cnt.values()]):
	print(-1)
else:
	ans = sum([v for v in cnt.values() if v > 0]) // 2
	print(ans)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(da, db) = ({}, {})
for x in a:
	da[x] = da.get(x, 0) + 1
for x in b:
	db[x] = db.get(x, 0) + 1
ansa = 0
for key in da:
	v = da[key] + db.get(key, 0)
	if v % 2 != 0:
		ansa = -1
		break
	elif da[key] > v // 2:
		ansa += da[key] - v // 2
ansb = 0
for key in db:
	v = db[key] + da.get(key, 0)
	if v % 2 != 0:
		ansb = -1
		break
	elif db[key] > v // 2:
		ansb += db[key] - v // 2
if ansa != ansb:
	print(-1)
else:
	print(ansa)


n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
oz1 = []
oz2 = []
for i in range(1, 6):
	oz1.append((a.count(i) + b.count(i)) % 2)
	oz2.append((a.count(i) + b.count(i)) // 2)
if 1 in oz1:
	print(-1)
else:
	rez = 0
	for i in range(1, 6):
		if a.count(i) > oz2[i - 1]:
			rez += a.count(i) - oz2[i - 1]
	print(rez)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(1, 6):
	x = a.count(i)
	y = b.count(i)
	if (x + y) % 2 == 0:
		res += abs(x - y) // 2
	else:
		exit(print(-1))
print(res // 2)


import sys
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
b = Counter(map(int, input().split()))
counta = 0
countb = 0
for i in range(1, 5 + 1):
	diff = abs(a[i] - b[i])
	if diff % 2:
		print(-1)
		sys.exit(0)
	if a[i] < b[i]:
		countb += int(diff / 2)
	if b[i] < a[i]:
		counta += int(diff / 2)
if counta != countb:
	print(-1)
	sys.exit(0)
print(counta)


from collections import Counter
n = int(input())
c1 = Counter([int(x) for x in input().split()])
c2 = Counter([int(x) for x in input().split()])
s = 0
for i in range(1, 6):
	d = abs(c1.get(i, 0) - c2.get(i, 0))
	if d % 2:
		print(-1)
		exit()
	s += d // 2
print(s // 2)


n = int(input())
groupA = list(map(int, input().split()))
groupB = list(map(int, input().split()))

def num_switches(n, groupA, groupB):
	diff = [0, 0, 0, 0, 0]
	for score in range(1, 6):
		if abs(groupA.count(score) - groupB.count(score)) % 2 == 1:
			return -1
		else:
			diff[score - 1] = abs(groupA.count(score) - groupB.count(score))
	if sum(diff) % 4 != 0:
		return -1
	else:
		return sum(diff) // 4
print(num_switches(n, groupA, groupB))


n = int(input())
groupA = [int(x) for x in input().split()]
groupB = [int(x) for x in input().split()]
a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
b = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
ans = 0
for i in range(n):
	a[groupA[i]] += 1
	b[groupB[i]] += 1
for i in a.keys():
	if (a[i] + b[i]) % 2 != 0:
		print(-1)
		exit()
	ans += abs(int((a[i] + b[i]) / 2) - a[i])
print(int(ans / 2))


n = int(input())
a = [int(inp) for inp in input().split()]
b = [int(inp) for inp in input().split()]
dictionary = [0] * 6
for num in a:
	dictionary[num] += 1
for num in b:
	dictionary[num] -= 1
count = 0
for num in dictionary:
	if abs(num) % 2 != 0:
		count = -1
		break
	else:
		count += max(0, num)
print(count // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [a.count(i) for i in range(1, 6)]
B = [b.count(i) for i in range(1, 6)]
cnt = 0
for j in range(5):
	if (A[j] + B[j]) % 2 != 0:
		print(-1)
		exit()
	cnt += abs(A[j] - B[j])
print(cnt // 4)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0] * 5
b = [0] * 5
for j in range(n):
	a[A[j] - 1] += 1
	b[B[j] - 1] += 1
per = 0
for j in range(5):
	if (a[j] + b[j]) % 2 == 1:
		per = 1
		break
if per == 1:
	print(-1)
else:
	ans = 0
	for j in range(5):
		if a[j] > b[j]:
			ans += (a[j] - b[j]) // 2
	print(ans)


import sys
from math import ceil
read = lambda : sys.stdin.readline().strip()
write = lambda x: sys.stdout.write(x + '\n')
N = int(read())
SA = list(map(int, read().split()))
SB = list(map(int, read().split()))
arrA = [0 for _ in range(5)]
arrB = [0 for _ in range(5)]
for i in range(N):
	arrA[SA[i] - 1] += 1
	arrB[SB[i] - 1] += 1
result = 0
for i in range(5):
	s = arrA[i] + arrB[i]
	diff = abs(arrA[i] - arrB[i])
	diff //= 2
	if s % 2:
		result = -1
		break
	result += diff
if result > 0:
	result = int(ceil(result / 2))
write(str(result))


n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
freq = [0] * 6
freq_a = [0] * 6
freq_b = [0] * 6
for i in A:
	freq[i] += 1
	freq_a[i] += 1
for i in B:
	freq[i] += 1
	freq_b[i] += 1
ans = 0
for i in range(1, 6):
	if freq[i] % 2:
		print(-1)
		exit()
	ans += abs(freq_a[i] - freq_b[i]) // 2
print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if (a.count(1) + b.count(1)) % 2 != 0 or (a.count(2) + b.count(2)) % 2 != 0 or (a.count(3) + b.count(3)) % 2 != 0 or ((a.count(4) + b.count(4)) % 2 != 0) or ((a.count(5) + b.count(5)) % 2 != 0):
	print(-1)
else:
	k = 0
	k += abs(a.count(1) - b.count(1)) // 2
	k += abs(a.count(2) - b.count(2)) // 2
	k += abs(a.count(3) - b.count(3)) // 2
	k += abs(a.count(4) - b.count(4)) // 2
	k += abs(a.count(5) - b.count(5)) // 2
	print(k // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
exchanges = 0
A = [0] * 5
for x in a:
	A[x - 1] += 1
B = [0] * 5
for x in b:
	B[x - 1] += 1
for x in range(5):
	if (A[x] + B[x]) % 2 == 1:
		exchanges = -1
		break
if exchanges != -1:
	total = 0
	for x in range(5):
		total += abs(A[x] - B[x])
	total = total // 4
	exchanges = total
print(exchanges)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
n = INT()
a = LIST()
b = LIST()
freq1 = [0] * 6
freq2 = [0] * 6
for i in a:
	freq1[i] += 1
for i in b:
	freq2[i] += 1
c = a + b
c2 = Counter(c)
c3 = c2.values()
flag = True
for i in c3:
	if i % 2 != 0:
		flag = False
		break
if not flag:
	print('-1')
	exit()
ans = 0
for i in range(1, 5 + 1):
	z = abs(freq1[i] - freq2[i]) // 2
	ans += z
print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = [0 for x in range(100)]
for x in a:
	count[x] += 1
for x in b:
	count[x] -= 1
for x in range(100):
	if count[x] < 0:
		count[x] = abs(count[x])
	if count[x] % 2 != 0:
		print(-1)
		exit()
total = sum(count) // 2
if total % 2 != 0:
	print(-1)
else:
	print(total // 2)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = Counter(a)
cb = Counter(b)

def solve():
	ans = 0
	balance = {}
	for mark in range(1, 6):
		c1 = ca.get(mark, 0)
		c2 = cb.get(mark, 0)
		s = c1 + c2
		if s % 2 != 0:
			return -1
		balance[mark] = c1 - s / 2
	if sum(balance.values()) != 0:
		return -1
	return int(sum(map(abs, balance.values())) / 2)
print(solve())


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
counterA = [0, 0, 0, 0, 0]
counterB = [0, 0, 0, 0, 0]
for i in range(n):
	counterA[a[i] - 1] += 1
for i in range(n):
	counterB[b[i] - 1] += 1
anyCountOdd = False
for i in range(5):
	if (counterA[i] + counterB[i]) % 2 == 1:
		anyCountOdd = True
		break
if anyCountOdd:
	print('-1')
else:
	exchanges = 0
	for i in range(5):
		midValue = (counterA[i] + counterB[i]) // 2
		if counterA[i] > counterB[i]:
			exchanges += counterA[i] - midValue
		else:
			exchanges += counterB[i] - midValue
	exchanges //= 2
	print(exchanges)


from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
b = Counter(list(map(int, input().split())))
possible = True
for i in range(1, 6):
	if (a[i] + b[i]) % 2:
		possible = False
		break
if not possible:
	print(-1)
else:
	ans = 0
	for i in range(1, 6):
		tot = (a[i] + b[i]) // 2
		if a[i] < tot:
			ans += tot - a[i]
	print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ex = 0
c = 0
for i in range(1, 6):
	a1 = a.count(i)
	b1 = b.count(i)
	x = a1 + b1
	if x % 2 != 0:
		c = 1
		break
	else:
		ex += x // 2 - min(a1, b1)
if c == 1:
	print(-1)
else:
	print(ex // 2)


from collections import Counter
n = int(input().strip())
ca = Counter([int(x) for x in input().strip().split(' ')])
cb = Counter([int(x) for x in input().strip().split(' ')])
cnt = 0
for i in range(1, 6):
	if (ca[i] + cb[i]) % 2 != 0:
		print(-1)
		exit(0)
	else:
		cnt += abs(ca[i] - (ca[i] + cb[i]) / 2)
print(int(cnt / 2))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
do = True
cnt = [0] * 5
ans = 0
for i in range(n):
	cnt[a[i] - 1] += 1
	cnt[b[i] - 1] -= 1
for i in range(5):
	if cnt[i] % 2 == 1:
		do = False
		break
if not do:
	print('-1')
else:
	for i in range(5):
		ans += abs(cnt[i])
	print(ans // 4)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = collections.Counter(LI())
	b = collections.Counter(LI())
	ks = set(a.keys()) | set(b.keys())
	r = 0
	for k in ks:
		s = abs(a[k] - b[k])
		if s % 2 == 1:
			return -1
		r += s
	return r // 4
print(main())


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
fra = [0] * 6
frb = [0] * 6
for i in a:
	fra[i] += 1
for i in b:
	frb[i] += 1
p = 0
ans = 0
f = True
for i in range(1, 6):
	r = fra[i] - frb[i]
	if r % 2 == 1:
		f = False
		break
	elif r >= 0:
		ans += r // 2
		p += r // 2
	else:
		p += r // 2
if f and p == 0:
	print(ans)
else:
	print(-1)


n = int(input())
(perfsA, perfsB) = ([0, 0, 0, 0, 0], [0, 0, 0, 0, 0])
(list1, list2) = (input().split(), input().split())
for num in list1:
	num = int(num)
	perfsA[num - 1] += 1
for num in list2:
	num = int(num)
	perfsB[num - 1] += 1
swips = 0
for i in range(0, 5):
	if abs(perfsA[i] - perfsB[i]) % 2 == 1:
		swips = -1
		break
	swips += abs(perfsB[i] - perfsA[i]) / 2
if swips % 2 == 1:
	print(-1)
else:
	print(int(swips / 2))


input()
a = [0 for i in range(6)]
b = [0 for i in range(6)]
for i in list(map(int, input().split())):
	a[i] += 1
for i in list(map(int, input().split())):
	b[i] += 1
ans = 0
for i in range(6):
	if (a[i] + b[i]) % 2 > 0:
		print('-1')
		exit(0)
	ans += abs(a[i] - (a[i] + b[i]) // 2)
print(ans // 2)


input()
fst = [int(x) for x in input().split()]
snd = [int(x) for x in input().split()]

def count(arr):
	res = {i: 0 for i in range(1, 6)}
	for i in arr:
		res[i] += 1
	return res

def solve():
	total = count(fst + snd)
	fst_ = count(fst)
	snd_ = count(snd)
	for v in total.values():
		if v % 2 != 0:
			return -1
	res = 0
	for (k, v) in fst_.items():
		diff = v - total[k] // 2
		res += diff if diff > 0 else 0
	return res
print(solve())


n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
w = True
ans = 0
for i in range(1, 6):
	Sum = a.count(i) + b.count(i)
	if Sum % 2 == 1:
		w = False
	ans += abs(a.count(i) - b.count(i))
if ans == int(ans) and w:
	print(int(ans // 4))
else:
	print('-1')


n = int(input())
a = []
b = []
y = input()
x = y.split()
for i in range(n):
	a.append(int(x[i]))
y = input()
x = y.split()
for i in range(n):
	b.append(int(x[i]))
a1 = abs(a.count(1) - b.count(1))
a2 = abs(a.count(2) - b.count(2))
a3 = abs(a.count(3) - b.count(3))
a4 = abs(a.count(4) - b.count(4))
a5 = abs(a.count(5) - b.count(5))
j = [a1, a2, a3, a4, a5]
j.sort()
if a1 % 2 == 0 and a2 % 2 == 0 and (a3 % 2 == 0) and (a4 % 2 == 0) and (a5 % 2 == 0):
	if (j[4] + j[3] + j[2] + j[1] + j[0]) / 2 % 2 == 0:
		print(int((j[4] + j[3] + j[2] + j[1] + j[0]) / 4))
	else:
		print(-1)
else:
	print(-1)


a = int(input())
b_ = input().split()
c_ = input().split()

def f(a, b_, c_):
	d1 = dict()
	d2 = dict()
	d = dict()
	for i in b_:
		if i not in d1:
			d1[i] = 0
		if i not in d:
			d[i] = 0
		d1[i] += 1
		d[i] += 1
	for j in c_:
		if j not in d2:
			d2[j] = 0
		if j not in d:
			d[j] = 0
		d2[j] += 1
		d[j] += 1
	ans = 0
	for i in d:
		if d[i] % 2:
			return -1
		else:
			if i not in d2:
				d2[i] = 0
			if i not in d1:
				d1[i] = 0
			ans += abs((d1[i] + d2[i]) // 2 - d1[i])
	return ans // 2
print(f(a, b_, c_))


n = int(input())
a = input()
b = input()
w = 0
s = 0
p = 0
leva = []
levb = []
A = [int(s) for s in a.split()]
B = [int(s) for s in b.split()]
for k in range(5):
	leva.append(0)
	levb.append(0)
	for i in range(n):
		if A[i] == k + 1:
			leva[k] += 1
		if B[i] == k + 1:
			levb[k] += 1
for i in range(5):
	w += leva[i] - levb[i]
	s += abs(leva[i] - levb[i]) / 4
	if (leva[i] + levb[i]) % 2 != 0:
		p = -1
if w == 0 and s % 1 == 0 and (p == 0):
	print(int(s))
else:
	print(-1)


n = int(input())
g1 = list(map(int, input().split()))
g2 = list(map(int, input().split()))
(G1, G2) = ({x: g1.count(x) for x in range(1, 6)}, {x: g2.count(x) for x in range(1, 6)})

def solve():
	ans = 0
	for i in range(1, 6):
		curr = G1[i] + G2[i]
		if curr & 1:
			return '-1'
		else:
			ans += max(0, G1[i] - curr // 2)
	return ans
print(solve())


N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ans = 0
for i in range(1, 6):
	a = As.count(i)
	b = Bs.count(i)
	if abs(a - b) % 2 == 1:
		ans = -2
		break
	else:
		ans += abs(a - b) // 2
print(ans // 2)


n = int(input().strip())
cl1 = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
cl2 = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
x = list(map(int, input().strip().split(' ')))
for i in x:
	cl1[i] += 1
x = list(map(int, input().strip().split(' ')))
for i in x:
	cl2[i] += 1
d1 = 0
d2 = 0
flage = True
for i in range(1, 6):
	if cl1[i] > cl2[i]:
		t = cl1[i] - cl2[i]
		if t % 2 == 0:
			d1 += t / 2
		else:
			flage = False
			print(-1)
			break
	elif cl2[i] > cl1[i]:
		t = cl2[i] - cl1[i]
		if t % 2 == 0:
			d2 += t / 2
		else:
			flage = False
			print(-1)
			break
if flage:
	if d1 == d2:
		print(int(d1))
	else:
		print(-1)


z = lambda : {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
input()
b = z()
c = z()
s = s1 = n = 0
for (i, j) in zip(map(int, input().split()), map(int, input().split())):
	b[i] += 1
	c[j] += 1
for i in b:
	z1 = b[i] + c[i]
	if z1 & 1:
		exit(print(-1))
	if z1 // 2 - b[i] > 0:
		n += z1 // 2 - b[i]
	s += z1 // 2 - b[i]
	s1 += z1 // 2 - c[i]
print(n if s == s1 else -1)


import math
n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
k = 0
s = 0
for i in range(1, 6):
	x = a.count(i)
	y = b.count(i)
	if (x + y) % 2 != 0:
		k = 1
		break
	else:
		s += abs(x - y)
if k == 1 or s % 4 != 0:
	print(-1)
else:
	print(s // 4)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ax = [0, 0, 0, 0, 0, 0]
bx = [0, 0, 0, 0, 0, 0]
for i in range(n):
	ax[a[i]] += 1
	bx[b[i]] += 1
ans = 0
for i in range(6):
	if (ax[i] + bx[i]) % 2 == 1:
		ans = -1
		break
	else:
		ans += abs((ax[i] - bx[i]) // 2)
print(ans // 2)


n = int(input())
G = {}
s = 0
for i in range(1, 6):
	G[i] = 0
for x in map(int, input().split()):
	G[x] += 1
for x in map(int, input().split()):
	G[x] -= 1
for i in range(1, 6):
	if G[i] % 2 == 1:
		print(-1)
		exit(0)
	s += abs(G[i])
print(s // 4)


n = int(input())
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))
a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
b = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for i in ta:
	a[i] = a.get(i, 0) + 1
for i in tb:
	b[i] = b.get(i, 0) + 1
it = 0
for key in a:
	k = a[key] - b[key]
	if k % 2 == 1:
		print(-1)
		exit()
	k //= 2
	it += abs(k)
if it % 2 == 1:
	print(-1)
else:
	print(it // 2)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
for i in range(1, 6):
	in_A = A.count(i)
	in_B = B.count(i)
	if (in_A + in_B) % 2 != 0:
		print(-1)
		break
	else:
		k += abs(in_A - (in_A + in_B) // 2)
else:
	print(k // 2)


n = int(input())
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
(c1, d1, e1, f1, g1) = (0, 0, 0, 0, 0)
(c2, d2, e2, f2, g2) = (0, 0, 0, 0, 0)
for i in a:
	if i == 1:
		c1 += 1
	elif i == 2:
		d1 += 1
	elif i == 3:
		e1 += 1
	elif i == 4:
		f1 += 1
	else:
		g1 += 1
for i in b:
	if i == 1:
		c2 += 1
	elif i == 2:
		d2 += 1
	elif i == 3:
		e2 += 1
	elif i == 4:
		f2 += 1
	else:
		g2 += 1
if c1 + c2 & 1 or d1 + d2 & 1 or e1 + e2 & 1 or f1 + f2 & 1 or g1 + g2 & 1:
	print(-1)
else:
	print((abs((c1 + c2) // 2 - c1) + abs((d1 + d2) // 2 - d1) + abs((e1 + e2) // 2 - e1) + abs((f1 + f2) // 2 - f1) + abs((g1 + g2) // 2 - g1)) // 2)


from sys import stdin, stdout
class1 = []
class2 = []
data_length = int(stdin.readline())
c1 = map(int, stdin.readline().split())
c2 = map(int, stdin.readline().split())
c1d = {}
c2d = {}
for mark in c1:
	c1d[mark] = c1d.get(mark, 0) + 1
for mark in c2:
	c2d[mark] = c2d.get(mark, 0) + 1
perm = 0
for mark in range(1, 6):
	if (c1d.get(mark, 0) + c2d.get(mark, 0)) % 2 == 1:
		stdout.write('-1' + '\n')
		exit(0)
diff = 0
for mark in range(1, 6):
	diff += abs(c1d.get(mark, 0) - c2d.get(mark, 0))
stdout.write(str(diff // 4) + '\n')


n = int(input())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
a = {1: al.count(1), 2: al.count(2), 3: al.count(3), 4: al.count(4), 5: al.count(5)}
b = {1: bl.count(1), 2: bl.count(2), 3: bl.count(3), 4: bl.count(4), 5: bl.count(5)}
possible = True
for key in a.keys():
	if (a[key] + b[key]) % 2 != 0:
		possible = False
		break
if possible:
	swaps = 0
	for key in a.keys():
		if a[key] > b[key]:
			swaps += (a[key] - b[key]) // 2
	print(swaps)
else:
	print(-1)


a = int(input(''))
lista = list(map(int, input().split(' ')))
listb = list(map(int, input().split(' ')))
dif = [0]
for i in range(1, 6, 1):
	dif.append(lista.count(i) - listb.count(i))
count = sum(dif)
if count == 0:
	for i in range(1, 6, 1):
		dif[i] = abs(dif[i])
		if dif[i] % 2 != 0:
			print('-1')
			exit()
	print(int(sum(dif) / 4))
else:
	print('-1')


def Can():
	sum = 0
	for i in range(1, 6):
		if (mapa1[i] + mapa2[i]) % 2 == 1:
			return -1
		else:
			sum += abs((mapa1[i] + mapa2[i]) / 2 - mapa1[i])
	return int(sum / 2)
n = int(input())
l1 = l2 = []
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
mapa1 = {}
mapa2 = {}
for i in range(1, 6):
	mapa1[i] = 0
	mapa2[i] = 0
for i in range(0, n):
	mapa1[l1[i]] += 1
	mapa2[l2[i]] += 1
print(Can())


n = int(input())
A = list(map(int, input().split()))
a = [0] * 6
B = list(map(int, input().split()))
b = [0] * 6
for i in A:
	if i == 1:
		a[1] += 1
	if i == 2:
		a[2] += 1
	if i == 3:
		a[3] += 1
	if i == 4:
		a[4] += 1
	if i == 5:
		a[5] += 1
for i in B:
	if i == 1:
		b[1] += 1
	if i == 2:
		b[2] += 1
	if i == 3:
		b[3] += 1
	if i == 4:
		b[4] += 1
	if i == 5:
		b[5] += 1
ans = 0
f = True
for i in range(1, 6):
	if (a[i] + b[i]) % 2 == 1:
		f = False
if f:
	for i in range(1, 6):
		ans += abs(a[i] - (a[i] + b[i]) // 2)
if f:
	print(ans // 2)
else:
	print(-1)


n = int(input())
A = dict()
for i in range(1, 6):
	A[i] = 0
lA = list(map(int, input().split()))
for la in lA:
	A[la] += 1
B = dict()
for i in range(1, 6):
	B[i] = 0
lB = list(map(int, input().split()))
for lb in lB:
	B[lb] += 1
cnt = 0
for i in range(1, 6):
	a = abs(B[i] - A[i])
	if a % 2 == 0:
		cnt += a // 2
	else:
		print(-1)
		break
else:
	if cnt % 2 == 0:
		print(cnt // 2)
	else:
		print(-1)


n = int(input())
a = [0] * 5
a1 = [0] * 5
a2 = [0] * 5
f = 0
s1 = input().split()
s2 = input().split()
for i in range(n):
	s1[i] = int(s1[i])
	s2[i] = int(s2[i])
	a[s1[i] - 1] += 1
	a1[s1[i] - 1] += 1
	a[s2[i] - 1] += 1
	a2[s2[i] - 1] += 1
for i in range(5):
	if a[i] % 2 == 1:
		f = 1
if f == 1:
	print(-1)
else:
	k = 0
	sss = 0
	for i in range(5):
		k = a1[i] - a2[i]
		if k < 0:
			k = -1 * k
		k = k // 2
		sss += k
	print(sss // 2)


n = int(input())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
(ar, br, r) = ([0] * 5, [0] * 5, [0] * 5)
for x in a:
	ar[x - 1] += 1
	r[x - 1] += 1
for x in b:
	br[x - 1] += 1
	r[x - 1] += 1
if sum([x % 2 for x in r]) > 0:
	print(-1)
else:
	ans = 0
	for i in range(5):
		ans += abs(ar[i] - br[i]) // 2
	print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c1 = [0] * 6
c2 = [0] * 6
for i in range(n):
	c1[a[i]] += 1
	c2[b[i]] += 1
x = 0
for i in range(6):
	if (c1[i] + c2[i]) % 2 != 0:
		print(-1)
		exit()
	else:
		x += abs(c1[i] - c2[i]) // 2
print(x // 2)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
s = set(a + b)
ab = a + b
for i in s:
	if ab.count(i) % 2 != 0:
		print(-1)
		exit(0)
for i in a:
	if i in b:
		b.remove(i)
print(len(b) // 2)


c = 1
cases = 1
while c <= cases:
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	al = []
	bl = []
	for i in range(1, 6):
		if (a.count(i) + b.count(i)) % 2 == 0:
			if a.count(i) > b.count(i):
				al.append((a.count(i) - b.count(i)) // 2)
			elif a.count(i) < b.count(i):
				bl.append((b.count(i) - a.count(i)) // 2)
		else:
			ans = -1
			break
	if sum(al) == sum(bl) and ans != -1:
		ans = sum(al)
	print(ans)
	c = c + 1


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum = [0, 0, 0, 0, 0]
countA = [0, 0, 0, 0, 0]
countB = [0, 0, 0, 0, 0]
flag = 0
for x in range(0, n):
	for i in range(0, 5):
		if a[x] == i + 1:
			sum[i] += 1
			countA[i] += 1
		if b[x] == i + 1:
			sum[i] += 1
			countB[i] += 1
ans = 0
for i in range(0, 5):
	ans += abs(sum[i] / 2 - countA[i])
if ans % 2 == 1:
	print('-1')
elif sum[0] % 2 == 1:
	print('-1')
elif sum[1] % 2 == 1:
	print('-1')
elif sum[2] % 2 == 1:
	print('-1')
elif sum[3] % 2 == 1:
	print('-1')
elif sum[4] % 2 == 1:
	print('-1')
else:
	print(int(ans / 2))


input()
(A, B) = (input(), input())
D = [abs(A.count(x) - B.count(x)) for x in '12345']
print(-1 if any((d % 2 for d in D)) else sum(D) // 4)


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
v = [0] * 6
for i in a:
	v[i] += 1
for i in b:
	v[i] -= 1
for i in v:
	if i % 2:
		print(-1)
		break
else:
	print(sum([abs(i) for i in v]) // 4)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
fa = [0] * 6
fb = [0] * 6
for i in a:
	fa[i] += 1
for i in b:
	fb[i] += 1
ans = 0
for i in range(6):
	xx = fa[i] + fb[i]
	if xx % 2 == 1:
		print(-1)
		exit()
	else:
		xx = xx // 2
		ans += min(abs(xx - fa[i]), abs(xx - fb[i]))
print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list(map(int, input().split()))
b.sort()
d = [0, 0, 0, 0, 0, 0]
for i in a:
	d[i] += 1
for i in b:
	d[i] -= 1
if any((i & 1 for i in d)):
	print('-1')
else:
	ans = 0
	for i in range(1, 6):
		ans += abs(d[i])
	print(ans // 2 // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0, 0, 0, 0, 0]
d = [0, 0, 0, 0, 0]
for x in range(0, n):
	c[a[x] - 1] = c[a[x] - 1] + 1
	d[b[x] - 1] = d[b[x] - 1] + 1

def dingle():
	for x in range(0, 5):
		if (c[x] + d[x]) % 2 != 0:
			return -1
	f = 0
	for x in range(0, 5):
		f = f + abs((c[x] - d[x]) // 2)
	return f // 2
print(dingle())


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
n = I()
a = li()
b = li()
ans = 0
c = [0 for i in range(6)]
ac = [0 for i in range(6)]
for i in range(n):
	c[a[i]] += 1
	ac[a[i]] += 1
	c[b[i]] += 1
for i in range(6):
	if c[i] % 2 != 0:
		print(-1)
		exit()
	else:
		c[i] //= 2
for i in range(6):
	ans += max(0, ac[i] - c[i])
print(ans)


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
counts = [0, 0, 0, 0, 0, 0]
for i in range(n):
	counts[a[i]] += 1
	counts[b[i]] -= 1
can = True
for i in range(1, 6):
	if counts[i] % 2 != 0:
		can = False
		break
ans = -1
if can:
	ans = 0
	for i in range(1, 6):
		ans += abs(counts[i])
	ans //= 4
print(ans)


def abs(x):
	return x if x >= 0 else -x
a = [0] * 5
b = a[:]
n = int(input())
first = input().split()
second = input().split()
for i in first:
	a[int(i) - 1] += 1
for i in second:
	b[int(i) - 1] += 1
flag = False
sum = 0
for i in range(5):
	x = abs(a[i] - b[i])
	if x % 2 == 1:
		flag = True
		break
	sum += x // 2
if flag:
	print('-1')
else:
	print(sum // 2)


n = int(input())
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
ans = 0
count1 = [0, 0, 0, 0, 0, 0]
count2 = [0, 0, 0, 0, 0, 0]
flag = True
for i in range(1, 6):
	s = x1.count(i) + x2.count(i)
	count1[i] = x1.count(i)
	count2[i] = x2.count(i)
	if s % 2 == 1:
		flag = False
		break
if flag:
	x1.sort()
	x2.sort()
	for i in range(1, 6):
		for j in range(min(count1[i], count2[i])):
			x1.remove(i)
			x2.remove(i)
			count1[i] -= 1
			count2[i] -= 1
	l = len(x1)
	print(l // 2)
else:
	print(-1)


from collections import Counter
n = int(input())
a = input().split(' ')
b = input().split(' ')
aa = Counter()
bb = Counter()
for x in a:
	aa[x] += 1
for x in b:
	bb[x] += 1
mm = Counter()
possible = True
for x in ('1', '2', '3', '4', '5'):
	if (aa[x] + bb[x]) % 2 != 0:
		possible = False
	else:
		mm[x] = (aa[x] + bb[x]) // 2
if not possible:
	print('-1')
else:
	print(sum((abs(aa[x] - mm[x]) for x in ('1', '2', '3', '4', '5'))) // 2)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
count = [0] * 6
for i in range(1, 6):
	count[i] = a.count(i) - b.count(i)
ans = 0
for i in range(1, 6):
	for j in range(i + 1, 6):
		if count[i] * count[j] < 0:
			t = min(abs(count[i]), abs(count[j])) // 2
			ans += t
			count[i] += t * 2 if count[i] < 0 else -t * 2
			count[j] += t * 2 if count[j] < 0 else -t * 2
if count.count(0) == 6:
	print(ans)
else:
	print(-1)


from collections import Counter
n = int(input())
class_a = [int(x) for x in input().split()]
class_b = [int(x) for x in input().split()]
A = Counter(class_a)
B = Counter(class_b)
delta = 0
for grade in range(1, 6):
	if (A[grade] + B[grade]) % 2 == 1:
		print(-1)
		exit()
	delta += abs(A[grade] - B[grade])
print(delta // 4)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
d1 = [0] * 6
d2 = [0] * 6
for x in l1:
	d1[x] += 1
for x in l2:
	d2[x] += 1
ans = 0
for i in range(6):
	if (d1[i] + d2[i]) % 2:
		print(-1)
		break
	ans += abs(d1[i] - d2[i])
else:
	print(ans // 4)


from collections import Counter
_ERROR = -1

def get_count_change(count, A_eval, B_eval):
	if count != len(A_eval) != len(B_eval) or count == 0:
		return _ERROR
	eval_counter_A = Counter(A_eval)
	eval_counter_B = Counter(B_eval)
	common_counter = eval_counter_A + eval_counter_B
	for (item, value) in common_counter.items():
		if value % 2 != 0:
			return _ERROR
	give_students_A = {item: value - common_counter[item] // 2 for (item, value) in eval_counter_A.items() if value - common_counter[item] // 2 > 0}
	give_students_B = {item: value - common_counter[item] // 2 for (item, value) in eval_counter_B.items() if value - common_counter[item] // 2 > 0}
	summ_A = sum(give_students_A.values())
	summ_B = sum(give_students_B.values())
	if summ_A == summ_B:
		return summ_A
	else:
		return _ERROR

def main():
	count = int(input().strip())
	A_eval = tuple(map(int, input().strip().split()))
	B_eval = tuple(map(int, input().strip().split()))
	print(get_count_change(count, A_eval, B_eval))
main()


n = int(input())
a = map(int, input().strip().split())
b = map(int, input().strip().split())
cnta = 6 * [0]
cntb = cnta.copy()
for (x, y) in zip(a, b):
	cnta[x] += 1
	cntb[y] += 1
ok = True
res = 0
for (x, y) in zip(cnta, cntb):
	res += abs(x - y)
	if abs(x + y) % 2 != 0:
		ok = False
		break
if ok:
	res //= 4
else:
	res = -1
print(res)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ha = [0 for i in range(5)]
hb = [0 for i in range(5)]
for i in range(n):
	ha[a[i] - 1] += 1
	hb[b[i] - 1] += 1
res = 0
for i in range(5):
	if abs(ha[i] - hb[i]) % 2 != 0 and ha[i] != hb[i]:
		print('-1')
		exit(0)
	res += abs(ha[i] - hb[i])
res = res // 2
res = res // 2
print(res)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ma = [0] * 5
mb = [0] * 5
for (a, b) in zip(A, B):
	ma[a - 1] += 1
	mb[b - 1] += 1
ca = 0
cb = 0
for (a, b) in zip(ma, mb):
	if (a + b) % 2 != 0:
		print(-1)
		exit()
	if a - b > 0:
		ca += (a - b) // 2
	elif a - b < 0:
		cb += (b - a) // 2
if ca == cb:
	print(ca)
else:
	print(-1)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
w = 0
ac = [0 for i in range(0, 6)]
bc = [0 for i in range(0, 6)]
for i in range(1, 6):
	ac[i] = a.count(i)
	bc[i] = b.count(i)
	if (ac[i] + bc[i]) % 2 != 0:
		w = 1
if w == 1:
	print(-1)
else:
	s1 = 0
	s2 = 0
	for i in range(1, 6):
		q = b.count(i) - (ac[i] + bc[i]) // 2
		if q > 0:
			s1 += q
		else:
			s2 += q
	if s1 == -s2:
		print(abs(s1))
	else:
		print(-1)


n = input()
a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
b = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
tmp = input().split(' ')
for i in tmp:
	a[int(i)] += 1
tmp = input().split(' ')
for i in tmp:
	b[int(i)] += 1
coba = 0
for i in range(1, 5 + 1):
	tmp = a[i] + b[i]
	if tmp % 2 != 0:
		coba = 1
	tmp = min(a[i], b[i])
	a[i] -= tmp
	b[i] -= tmp
if coba == 1:
	print('-1')
else:
	ans = 0
	for i in range(1, 5 + 1):
		ans += a[i] // 2
	for i in range(1, 5 + 1):
		ans += b[i] // 2
	ans = ans // 2
	print(ans)


n = input()
f = list(map(str, input().split()))
s = list(map(str, input().split()))
od = abs(f.count('1') - s.count('1'))
sd = abs(f.count('2') - s.count('2'))
td = abs(f.count('3') - s.count('3'))
fd = abs(f.count('4') - s.count('4'))
vd = abs(f.count('5') - s.count('5'))
if od % 2 == 0 and sd % 2 == 0 and (td % 2 == 0) and (fd % 2 == 0) and (vd % 2 == 0):
	print((od + sd + td + fd + vd) // 4)
else:
	print(-1)


I = lambda : list(map(int, input().split()))
s = int(input())
a = I()
b = I()
c = [a.count(i) for i in [1, 2, 3, 4, 5]]
d = [b.count(i) for i in [1, 2, 3, 4, 5]]
ans = 0
for (i, j) in zip(c, d):
	if (i - j) % 2:
		print(-1)
		quit()
	if i > j:
		ans += (i - j) // 2
print(ans)


n = int(input())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
if any((abs(a.count(x) - b.count(x)) % 2 == 1 for x in range(1, 6))):
	print(-1)
else:
	print(sum([abs(a.count(y) - b.count(y)) // 2 for y in range(1, 6)]) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [0 for i in range(5)]
for i in range(n):
	cnt[a[i] - 1] += 1
	cnt[b[i] - 1] -= 1
a = [1 for i in cnt if i % 2 != 0]
if a:
	print(-1)
else:
	print(sum((abs(i) for i in cnt)) // 4)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [0] * 5
for i in range(0, n):
	arr[a[i] - 1] += 1
	arr[b[i] - 1] -= 1
for i in range(0, 5):
	if arr[i] % 2 == 1:
		print(-1)
		exit(0)
	arr[i] = abs(arr[i]) // 2
print(sum(arr) // 2)


n = int(input())
A = map(int, input().split())
B = map(int, input().split())

def count_performance(group):
	count = [0] * 6
	for performance in group:
		count[performance] += 1
	return count[1:]
A_performance = count_performance(A)
B_performance = count_performance(B)
exchanges = 0
possible = True
for (a, b) in zip(A_performance, B_performance):
	diff = abs(a - b)
	if diff & 1:
		possible = False
		break
	exchanges += diff
print(exchanges // 4 if possible else -1)


def func():
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	A = [0] * 6
	B = [0] * 6
	for l in x:
		A[l] += 1
	for l in y:
		B[l] += 1
	res = 0
	for i in range(1, 6):
		if (A[i] - B[i]) % 2 != 0:
			return '-1'
		elif A[i] > B[i]:
			res += (A[i] - B[i]) / 2
	return int(res)
print(func())


f = int(input())
a = input()
a = [int(i) for i in a.split()]
b = input()
b = [int(i) for i in b.split()]
c = [0, 0, 0, 0, 0, 0]
cp = [0, 0, 0, 0, 0, 0]
ans = []
for i in a:
	c[i] += 1
for i in b:
	cp[i] += 1
t = 1
for i in range(len(c)):
	if (cp[i] + c[i]) % 2 == 1:
		print(-1)
		t = 0
		break
	else:
		ans.append(c[i] - (cp[i] + c[i]) // 2)
if t == 1:
	(pos, neg, su) = (0, 0, 0)
	for i in range(len(ans)):
		if ans[i] > 0:
			pos += ans[i]
		if ans[i] < 0:
			neg += ans[i]
		su += ans[i]
	if su < 0:
		print(-neg)
	if su == 0:
		print(pos)
	if su > 0:
		print(pos)


input()
a = [0] * 6
for i in [1, -1]:
	for x in map(int, input().split()):
		a[x] += i
s = sum((abs(x) for x in a))
print([s // 4, -1][any((x % 2 for x in a))])


n = int(input())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lc = [la.count(i + 1) for i in range(5)]
ld = [lc[i] + lb.count(i + 1) for i in range(5)]
for i in range(5):
	if ld[i] & 1:
		print(-1)
		break
else:
	print(sum([abs(lc[i] - ld[i] // 2) for i in range(5)]) // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
setab = set(a + b)
ab = a + b
for i in setab:
	if ab.count(i) % 2 == 1:
		print(-1)
		exit()
for j in a:
	if j in b:
		b.remove(j)
print(len(b) // 2)


n = int(input())
class_A = [int(x) for x in input().split(' ')]
class_B = [int(x) for x in input().split(' ')]
cnt = [0 for x in range(1, 6)]

def main():
	for mark in class_A:
		cnt[mark - 1] += 1
	for mark in class_B:
		cnt[mark - 1] -= 1
	for mark in cnt:
		if mark % 2 != 0:
			return -1
	c = 0
	for mark in cnt:
		c += abs(mark)
	return c // 4
print(main())


n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ch = True
oa = a.count(1)
ta = a.count(2)
tha = a.count(3)
fa = a.count(4)
fia = a.count(5)
ob = b.count(1)
tb = b.count(2)
thb = b.count(3)
fb = b.count(4)
fib = b.count(5)
o = 0
t = 0
th = 0
f = 0
fi = 0
if abs(oa - ob) % 2 != 0:
	ch = False
else:
	o = abs(oa - ob) // 2
if abs(ta - tb) % 2 != 0:
	ch = False
else:
	t = abs(ta - tb) // 2
if abs(tha - thb) % 2 != 0:
	ch = False
else:
	th = abs(tha - thb) // 2
if abs(fa - fb) % 2 != 0:
	ch = False
else:
	f = abs(fa - fb) // 2
if abs(fia - fib) % 2 != 0:
	ch = False
else:
	fi = abs(fia - fib) // 2
ans = o + t + th + f + fi
if ans % 2 != 0 or not ch:
	print('-1')
else:
	print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0] * 6
for v in a:
	aa[v] += 1
bb = [0] * 6
for v in b:
	bb[v] += 1
res = sum(map(lambda x, y: max(x - y, 0), aa, bb))
if any(map(lambda x, y: x - y & 1, aa, bb)):
	print(-1)
else:
	print(res // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = [0] * 6
ac = [0] * 6
for val in a:
	ac[val] += 1
	total[val] += 1
bc = [0] * 6
for val in b:
	bc[val] += 1
	total[val] += 1
possible = True
for i in range(len(total)):
	if total[i] % 2 != 0:
		possible = False
		break
if not possible:
	print(-1)
else:
	out = 0
	for i in range(len(ac)):
		out += abs(total[i] / 2 - ac[i]) / 2
	print(int(out))


n = int(input())
a = [int(ch) for ch in input() if ch is not ' ']
b = [int(ch) for ch in input() if ch is not ' ']
ls = [a.count(x) + b.count(x) for x in range(1, 6)]
(j, cnt) = (1, 0)
for i in ls:
	if i % 2 != 0:
		print('-1')
		break
	else:
		cnt += abs(a.count(j) - i // 2)
	j += 1
else:
	print(cnt // 2)


def f(a, b):
	n = 6
	d = [0] * n
	for i in range(len(a)):
		d[a[i]] += 1
		d[b[i]] -= 1
	if sum([d[i] % 2 > 0 for i in range(n)]) > 0:
		return -1
	return sum([d[i] >> 1 for i in range(n) if d[i] > 0])
_ = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(f(a, b))


n = int(input())
s = list(map(int, input().split()))
p = list(map(int, input().split()))
a1 = s.count(1)
a2 = s.count(2)
a3 = s.count(3)
a4 = s.count(4)
a5 = s.count(5)
b1 = p.count(1)
b2 = p.count(2)
b3 = p.count(3)
b4 = p.count(4)
b5 = p.count(5)
z1 = abs(a1 - b1)
z2 = abs(a2 - b2)
z3 = abs(a3 - b3)
z4 = abs(a4 - b4)
z5 = abs(a5 - b5)
ans1 = (z1 + z2 + z3 + z4 + z5) // 2
if z1 % 2 == 0 and z2 % 2 == 0 and (z3 % 2 == 0) and (z4 % 2 == 0) and (z2 % 2 == 0):
	if ans1 % 2 == 0:
		print(ans1 // 2)
	else:
		print('-1')
else:
	print('-1')


def ri():
	return map(int, input().split())
n = int(input())
a = list(ri())
b = list(ri())
ad = dict()
bd = dict()
for i in range(n):
	if not a[i] in ad:
		ad[a[i]] = 1
	else:
		ad[a[i]] += 1
	if not b[i] in bd:
		bd[b[i]] = 1
	else:
		bd[b[i]] += 1
ans = 0
for i in range(1, 6):
	ta = 0
	tb = 0
	if i in ad:
		ta += ad[i]
	if i in bd:
		tb += bd[i]
	if (ta + tb) % 2:
		print(-1)
		exit()
	else:
		ans += abs(ta - (ta + tb) // 2)
print(ans // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mas = [0] * 5
for i in range(n):
	mas[b[i] - 1] += 1
	mas[a[i] - 1] -= 1
answer = 0
for i in range(5):
	if mas[i] % 2 == 1:
		print(-1)
		break
	else:
		k = abs(mas[i])
		answer += k // 2
else:
	print(answer // 2)


n = int(input())
g1 = list(map(int, input().split()))
g2 = list(map(int, input().split()))
grade1 = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
grade2 = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
grades = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for i in g1:
	grades[i] += 1
	grade1[i] += 1
for i in g2:
	grades[i] += 1
	grade2[i] += 1
exch = 0
flag = 0
for i in range(1, 6):
	if grades[i] % 2:
		flag = -1
	if grade1[i] > grades[i] // 2:
		exch = exch + (grade1[i] - grades[i] // 2)
if flag == -1:
	print(flag)
else:
	print(exch)


from collections import defaultdict

def main():
	n = int(input())
	a = defaultdict(int)
	b = defaultdict(int)
	for x in map(int, input().split()):
		a[x] += 1
	for x in map(int, input().split()):
		b[x] += 1
	t1 = 0
	t2 = 0
	for x in range(1, 6):
		d = a[x] - b[x]
		if d % 2 == 1:
			print(-1)
			return
		d //= 2
		if d > 0:
			t1 += d
		elif d < 0:
			t2 -= d
	if t1 == t2:
		print(t1)
	else:
		print(-1)
main()


from collections import defaultdict
n = int(input())
aa = map(int, input().split())
bb = map(int, input().split())
q = defaultdict(int)
w = defaultdict(int)
e = defaultdict(int)
for a in aa:
	q[a] += 1
	e[a] += 1
for b in bb:
	w[b] += 1
	e[b] += 1
ans = 0
for i in range(1, 6):
	if e[i] % 2 != 0:
		ans = -1
		break
	ans += abs(q[i] - e[i] // 2)
print(ans // 2)


input()
(MyDict, All, Diff) = ({1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, 0)
for i in list(map(int, input().split())):
	MyDict[i] += 1
	All[i] += 1
for i in list(map(int, input().split())):
	All[i] += 1
for key in All.keys():
	if All[key] % 2 == 1:
		print(-1)
		exit()
	Diff += abs(All[key] // 2 - MyDict[key])
print(Diff // 2)


n = int(input())
import sys
t = list(map(int, input().split()))
p = list(map(int, input().split()))
t1 = [0, 0, 0, 0, 0]
p1 = [0, 0, 0, 0, 0]
for i in range(n):
	if t[i] == 1:
		t1[0] += 1
	elif t[i] == 2:
		t1[1] += 1
	elif t[i] == 3:
		t1[2] += 1
	elif t[i] == 4:
		t1[3] += 1
	elif t[i] == 5:
		t1[4] += 1
	if p[i] == 1:
		p1[0] += 1
	elif p[i] == 2:
		p1[1] += 1
	elif p[i] == 3:
		p1[2] += 1
	elif p[i] == 4:
		p1[3] += 1
	elif p[i] == 5:
		p1[4] += 1
s = 0
for i in range(5):
	if abs(t1[i] - p1[i]) % 2 != 0:
		print(-1)
		sys.exit()
	s += abs(t1[i] - p1[i]) // 2
print(s // 2)


def isEven(number):
	if number % 2 == 0:
		return True
	else:
		return False
studentCount = int(input())
gradesA = [int(x) for x in input().split(' ')]
gradesB = [int(x) for x in input().split(' ')]
gradeCountA = [0, 0, 0, 0, 0, 0]
gradeCountB = [0, 0, 0, 0, 0, 0]
for x in gradesA:
	gradeCountA[x] += 1
for x in gradesB:
	gradeCountB[x] += 1
for x in range(1, 6):
	if not isEven(gradeCountB[x] + gradeCountA[x]):
		print('-1')
		exit()
desiredGradeCount = [0, 0, 0, 0, 0, 0]
for x in range(1, 6):
	desiredGradeCount[x] = (gradeCountB[x] + gradeCountA[x]) / 2
change = 0
for x in range(1, 6):
	change += abs(desiredGradeCount[x] - gradeCountA[x])
print(str(int(change // 2)))


n = int(input().strip())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
a_d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
b_d = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for i in range(n):
	a_d[a[i]] += 1
for i in range(n):
	b_d[b[i]] += 1
cnt = 0
for i in range(1, 6):
	if (a_d[i] + b_d[i]) % 2:
		print(-1)
		break
	else:
		cnt += abs(a_d[i] - b_d[i]) // 2
else:
	print(cnt // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aCnt = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
bCnt = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for i in range(n):
	aCnt[a[i]] += 1
	bCnt[b[i]] += 1
out = 0
for i in range(1, 6):
	if abs(aCnt[i] - bCnt[i]) % 2 == 1:
		print('-1')
		exit()
	out += abs(aCnt[i] - bCnt[i]) // 2
print(out // 2)


n = int(input())
a1 = list(map(int, input().split(' ')))
b1 = list(map(int, input().split(' ')))
a = [0] * 6
b = [0] * 6
for i in range(n):
	a[a1[i]] += 1
	b[b1[i]] += 1
res = 0
qqq = 1
for i in range(6):
	if abs(a[i] - b[i]) % 2 != 0:
		print('-1')
		qqq = -1
		break
	res += abs(a[i] - b[i]) / 2
if qqq == 1:
	print(int(res / 2))


n = int(input())
a = [int(i) for i in input().strip().split(' ')]
b = [int(i) for i in input().strip().split(' ')]
assert len(a) == len(b) == n
A = [0] * 5
B = [0] * 5
for i in range(n):
	A[a[i] - 1] = A[a[i] - 1] + 1
	B[b[i] - 1] = B[b[i] - 1] + 1
atob = 0
btoa = 0
badInput = False
for i in range(5):
	if (A[i] + B[i]) % 2 != 0:
		badInput = True
		break
	if A[i] >= B[i]:
		atob = atob + (A[i] - B[i]) // 2
	else:
		btoa = btoa + (B[i] - A[i]) // 2
if badInput:
	print(-1)
else:
	assert btoa == atob
	print(atob)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
for i in a:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
for i in b:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
val = list(d.values())
somme = []
x = True
for i in val:
	if i % 2 != 0:
		x = False
		break
s = 0
neg = 0
pos = 0
if x:
	if len(val) == 1:
		print(0)
	else:
		for i in list(set(a)):
			if a.count(i) - d[i] // 2 < 0:
				neg += a.count(i) - d[i] // 2
			else:
				pos += a.count(i) - d[i] // 2
		s = min(abs(neg), pos) + abs(abs(neg) - pos)
		print(s)
else:
	print(-1)


for _ in range(1):
	n = int(input())
	arr = [int(i) for i in input().split()]
	brr = [int(i) for i in input().split()]
	f = 0
	c = [0 for i in range(6)]
	for i in range(n):
		c[arr[i]] += 1
	for i in range(n):
		c[brr[i]] -= 1
	for i in range(6):
		if c[i] % 2 == 1:
			f = 1
			break
	su = 0
	if f == 0:
		for i in range(6):
			su += abs(c[i])
		print(su // 4)
	else:
		print(-1)


n = int(input())
Sum = 0
classA = list(map(int, input().split()))
classB = list(map(int, input().split()))
w = False
for i in range(1, 6):
	if (classA.count(i) + classB.count(i)) % 2 == 1:
		w = True
		break
	else:
		Sum += abs(classA.count(i) - classB.count(i))
if w:
	print(-1)
else:
	print(int(Sum / 4))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
numa = [0] * 5
numb = [0] * 5
for i in a:
	numa[i - 1] += 1
for i in b:
	numb[i - 1] += 1
failed = False
for i in range(0, 5):
	if (numa[i] + numb[i]) % 2 == 1:
		failed = True
		break
steps = 0
if failed:
	print(-1)
else:
	for i in range(0, 5):
		steps += abs(numa[i] - numb[i]) / 2
	print(int(steps / 2))


n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A_grades = [0, 0, 0, 0, 0]
B_grades = [0, 0, 0, 0, 0]
for i in range(0, n):
	A_grades[A[i] - 1] += 1
	B_grades[B[i] - 1] += 1
l = 0
for i in range(0, 5):
	if (A_grades[i] + B_grades[i]) % 2 != 0:
		print(-1)
		l = 1
		break
dif = 0
for i in range(0, 5):
	dif += abs(A_grades[i] - B_grades[i])
if l == 0:
	print(dif // 4)


from collections import defaultdict
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
dictA = defaultdict(lambda : 0)
dictB = defaultdict(lambda : 0)
for x in A:
	dictA[x] += 1
for x in B:
	dictB[x] += 1
flag = True
for i in range(1, 6):
	if (dictA[i] + dictB[i]) % 2 is not 0:
		flag = False
		break
if not flag:
	print(-1)
else:
	count = 0
	for i in range(1, 6):
		if dictA[i] != dictB[i]:
			mid = (dictA[i] + dictB[i]) // 2
			count += mid - min(dictA[i], dictB[i])
	print(count // 2)


N = int(input())
L = list(map(int, input().split()))
R = list(map(int, input().split()))
L_cnt = {}
for i in range(1, 6):
	L_cnt[i] = L.count(i)
R_cnt = {}
for i in range(1, 6):
	R_cnt[i] = R.count(i)
sum_cnt = {}
for i in range(1, 6):
	sum_cnt[i] = L_cnt[i] + R_cnt[i]
	if sum_cnt[i] % 2 != 0:
		print('-1')
		exit()
ans = 0
for i in range(1, 6):
	if L_cnt[i] >= sum_cnt[i] // 2:
		ans += L_cnt[i] - sum_cnt[i] // 2
print(ans)


from collections import Counter
bad = False
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
counts_a = Counter(A)
counts_b = Counter(B)
counts_total = Counter(A + B)
swaps = 0
for i in range(1, 6):
	if counts_total[i] % 2 != 0:
		bad = True
	swaps += max(counts_a[i], counts_b[i]) - counts_total[i] // 2
if bad:
	print(-1)
else:
	print(swaps // 2)


import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(1, 6):
	f = a.count(i)
	s = b.count(i)
	if (f + s) % 2 != 0:
		print(-1)
		sys.exit(0)
	ans += abs(f - s) // 2
print(ans // 2)


from sys import stdin
from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a_d = defaultdict(int)
b_d = defaultdict(int)
for i in range(n):
	a_d[a[i]] += 1
	b_d[b[i]] += 1
f = True
ans = 0
for i in range(6):
	if (a_d[i] + b_d[i]) % 2:
		f = False
		break
	ans += abs(a_d[i] - b_d[i])
if f:
	print(ans // 4)
else:
	print(-1)


from sys import stdin, stdout
n = int(stdin.readline())
first = list(map(int, stdin.readline().split()))
second = list(map(int, stdin.readline().split()))
cntf = [0, 0, 0, 0, 0]
cnts = [0, 0, 0, 0, 0]
for i in range(n):
	cntf[first[i] - 1] += 1
	cnts[second[i] - 1] += 1
label = 1
for i in range(5):
	if (cntf[i] + cnts[i]) % 2:
		label = 0
if not label:
	stdout.write('-1')
else:
	ans = 0
	for i in range(5):
		m = (cntf[i] + cnts[i]) // 2
		ans += max(cntf[i] - m, 0)
	stdout.write(str(ans))


a = input()
b = input()
c = input()
_b = {}
_c = {}
b = [int(x) for x in b.split()]
c = [int(x) for x in c.split()]
for i in range(1, 6):
	_b[str(i)] = 0
	_c[str(i)] = 0
for index in b:
	if str(index) in _b:
		_b[str(index)] += 1
	else:
		_b[str(index)] = 1
for index in c:
	if str(index) in _c:
		_c[str(index)] += 1
	else:
		_c[str(index)] = 1
number_of_changes = 0
stopped = False
for i in range(1, 6):
	if _b[str(i)] == _c[str(i)]:
		continue
	if (_b[str(i)] + _c[str(i)]) % 2 != 0:
		stopped = True
		print(-1)
		break
	number_of_changes += abs(_b[str(i)] - _c[str(i)]) / 2
if not stopped:
	print(int(number_of_changes / 2))


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [0] * 6
d = [0] * 6
for i in range(n):
	c[a[i]] += 1
	d[b[i]] += 1

def compute():
	for i in range(1, 6):
		if (c[i] + d[i]) % 2 != 0:
			return -1
	x = 0
	y = 0
	for i in range(1, 6):
		if c[i] > d[i]:
			x += c[i] - d[i]
		elif d[i] > c[i]:
			y += d[i] - c[i]
	if x != y:
		return -1
	else:
		return x // 2
print(compute())


def f():
	n = int(input())
	i1 = input().strip().split()
	i2 = input().strip().split()
	a1 = [int(x) for x in i1]
	a2 = [int(x) for x in i2]
	b1 = [0, 0, 0, 0, 0]
	b2 = [0, 0, 0, 0, 0]
	d = [0, 0, 0, 0, 0]
	for i in a1:
		b1[i - 1] += 1
	for i in a2:
		b2[i - 1] += 1
	(sum, sum2) = (0, 0)
	for i in range(5):
		d[i] = b1[i] - b2[i]
		if d[i] % 2 != 0:
			print(-1)
			return
		sum += d[i]
		sum2 += abs(d[i])
	if sum != 0:
		print(-1)
	else:
		print(sum2 // 4)
f()


import sys

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def solve():
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	cntA = [0] * 5
	cntB = [0] * 5
	for a in A:
		cntA[a - 1] += 1
	for b in B:
		cntB[b - 1] += 1
	ans = 0
	for k in range(5):
		if abs(cntA[k] - cntB[k]) % 2:
			print(-1)
			return None
		else:
			ans += abs(cntA[k] - cntB[k])
	ans //= 4
	print(ans)
solve()


def solve(l):
	for i in range(5):
		if abs(l[i] & 1):
			return -1
	ans = 0
	for i in range(5):
		if l[i] > 0:
			ans += l[i] // 2
	return ans
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
l = [0] * 5
for i in a:
	l[i - 1] += 1
for i in b:
	l[i - 1] -= 1
print(solve(l))


n = int(input())
ara1 = list(map(int, input().split()))
ara2 = list(map(int, input().split()))
count1 = [0] * 6
count2 = [0] * 6
sum = 0
flag = 0
for a in ara1:
	count1[a] += 1
for a in ara2:
	count2[a] += 1
for i in range(6):
	if (count1[i] - count2[i]) % 2 == 1:
		print(-1)
		flag = 1
		break
	else:
		sum += abs(count1[i] - count2[i])
if flag == 0:
	print(sum // 4)


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def nconv(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
n = ii()
a = li()
b = li()
for i in range(5):
	if (a.count(i + 1) + b.count(i + 1)) % 2 != 0:
		print(-1)
		exit()
ans = 0
for i in range(5):
	ans += abs(a.count(i + 1) - b.count(i + 1)) // 2
print(ans // 2)


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
a = L()
b = L()
da = defaultdict(int)
db = defaultdict(int)
for i in a:
	da[i] += 1
for j in b:
	db[j] += 1
s = list(set(list(da.keys()) + list(db.keys())))
for i in s:
	if (da[i] + db[i]) % 2 == 1:
		print(-1)
		exit()
ans = 0
for i in set(a):
	if da[i] > (da[i] + db[i]) // 2:
		p = (da[i] + db[i]) // 2
		ans += abs(p - da[i])
for i in set(b):
	if db[i] > (da[i] + db[i]) // 2:
		p = (da[i] + db[i]) // 2
		ans += abs(p - db[i])
print(ans // 2)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(1, 6):
	if A.count(i) + B.count(i) & 1:
		exit(print('-1'))
	ans += abs(A.count(i) - B.count(i)) // 2
print(ans // 2)


n = int(input())
AScores = list(map(int, input().split()))
BScores = list(map(int, input().split()))
uniques = list()
for score in AScores:
	if score not in uniques:
		uniques.append(score)
for score in BScores:
	if score not in uniques:
		uniques.append(score)
switches = 0
for score in uniques:
	ACount = AScores.count(score)
	BCount = BScores.count(score)
	if (ACount + BCount) % 2 == 1:
		switches = -4
		break
	switches += abs(ACount - BCount)
print(int(switches / 4))


s = int(input())
a = input()
b = input()
changes = 0
for x in range(1, 6):
	a_c = a.count(str(x))
	b_c = b.count(str(x))
	if a_c % 2 != b_c % 2:
		print(-1)
		break
	changes += abs(a_c - b_c) // 2
else:
	print(changes // 2)


nb_pupil = int(input())
grp_1 = [int(x) for x in input().split()]
grp_2 = [int(x) for x in input().split()]
changed = 0
ans = -1
for i in range(1, 6):
	grp1 = grp_1.count(i)
	grp2 = grp_2.count(i)
	if not (grp1 + grp2) % 2:
		changed += abs(grp1 - grp2) // 2
		ans = 0
	else:
		ans = -1
		break
if ans != -1:
	print(changed // 2)
else:
	print(-1)


def calc():
	sum = 0
	for i in range(1, 6):
		a1 = a.count(i)
		a2 = b.count(i)
		if (a1 + a2) % 2 == 1:
			return -1
		sum += abs(a1 - a2)
	return sum // 4
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
print(calc())


def Pupils_redistribution():
	n = int(input())
	g1 = input().split()
	g1d = [0] * 5
	g2 = input().split()
	g2d = [0] * 5
	for i in g1:
		g1d[int(i) - 1] += 1
	for i in g2:
		g2d[int(i) - 1] += 1
	nd = [0] * 5
	for i in range(len(g1d)):
		a = g1d[i] - g2d[i]
		if a % 2 == 0:
			nd[i] = a / 2
		else:
			print('-1')
			break
	else:
		if sum(nd) == 0:
			sums = 0
			for i in nd:
				if i > 0:
					sums += i
			print(int(sums))
		else:
			print('-1')
Pupils_redistribution()


from sys import maxsize, stdout, stdin, stderr
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
S = lambda : stdin.readline().replace('\n', '').strip()

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
from collections import defaultdict
from collections import Counter
n = I()
a = lint()
b = lint()
cnt = [0] * 6
for i in range(n):
	cnt[a[i]] += 1
	cnt[b[i]] -= 1
s = 0
for i in cnt:
	if i % 2 != 0:
		stpr(-1)
		exit()
	elif i > 0:
		s += i
stpr(s // 2)


n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
al = [0] * 5
al1 = [0] * 5
al2 = [0] * 5
for i in l1:
	al[i - 1] += 1
	al1[i - 1] += 1
for i in l2:
	al[i - 1] += 1
	al2[i - 1] += 1
for i in al:
	if i % 2 == 1:
		print(-1)
		exit()
ans = 0
for i in range(5):
	ans += abs(al1[i] - al2[i])
print(ans // 4)


import sys

def input():
	return sys.stdin.readline()
n = int(input())
class_A = sorted(list(map(int, input().split())))
class_B = sorted(list(map(int, input().split())))
counts = [0] * 6
total = 0
for i in range(1, 6):
	counts[i] = class_A.count(i) + class_B.count(i)
	if counts[i] % 2:
		print(-1)
		sys.exit(0)
	counts[i] //= 2
for i in range(1, 6):
	total += abs(counts[i] - class_A.count(i))
print(total // 2)


c = 0
a = int(input())
(x, l) = [list(map(int, input().split())) for i in range(2)]
x.sort()
l.sort()
for i in range(1, 6):
	k = abs(x.count(i) - l.count(i))
	if k % 2 == 1:
		a = 0
		break
	else:
		c += k
print(c // 4 if c % 4 == 0 and a != 0 else -1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0, 0, 0, 0, 0]
for i in a:
	c[i - 1] += 1
for j in b:
	c[j - 1] -= 1
c = [abs(i) for i in c]
import sys
for i in c:
	if i % 2:
		print(-1)
		sys.exit(0)
print(sum(c) // 4)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
count = 0
a_dict = [a.count(1), a.count(2), a.count(3), a.count(4), a.count(5)]
b_dict = [b.count(1), b.count(2), b.count(3), b.count(4), b.count(5)]
possible = False
for i in range(5):
	numbers_count = a_dict[i] + b_dict[i]
	if numbers_count % 2 == 1:
		possible = False
		break
	else:
		possible = True
if a_dict[0] > b_dict[0]:
	count += (a_dict[0] - b_dict[0]) // 2
if a_dict[1] > b_dict[1]:
	count += (a_dict[1] - b_dict[1]) // 2
if a_dict[2] > b_dict[2]:
	count += (a_dict[2] - b_dict[2]) // 2
if a_dict[3] > b_dict[3]:
	count += (a_dict[3] - b_dict[3]) // 2
if a_dict[4] > b_dict[4]:
	count += (a_dict[4] - b_dict[4]) // 2
if possible:
	print(count)
else:
	print('-1')


import collections
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(c, l) = (0, [])
for i in range(1, 6):
	k = a.count(i) - b.count(i)
	if k % 2 == 0:
		l.append(k // 2)
	else:
		c = 1
		break
ans = 0
if c == 1:
	print('-1')
elif sum(l) != 0:
	print(-1)
else:
	for i in l:
		if i > 0:
			ans += i
	print(ans)


t = int(input())
foo = [int(x) for x in input().split()]
bar = [int(x) for x in input().split()]
d1 = dict()
d2 = dict()
for i in range(1, 6):
	d1[i] = foo.count(i)
for i in range(1, 6):
	d2[i] = bar.count(i)
over = 0
tt = 0
for i in range(1, 6):
	if d1[i] > d2[i]:
		a = d1[i] - d2[i]
		if a % 2 == 0:
			d2[i] += a // 2
			over += a // 2
			tt += a // 2
		else:
			print(-1)
			exit(0)
	elif d2[i] > d1[i]:
		a = d2[i] - d1[i]
		if a % 2 == 0:
			d1[i] += a // 2
			over -= a // 2
			tt += a // 2
		else:
			print(-1)
			exit(0)
if over == 0:
	print(tt // 2)
else:
	print(-1)


n = int(input())
R = lambda : list(map(int, input().split()))
(a1, a2) = (R(), R())
from collections import Counter
(c1, c2) = (Counter(a1), Counter(a2))
ans = 0
for i in range(1, 6):
	(v1, v2) = (c1.get(i, 0), c2.get(i, 0))
	if (v1 + v2) % 2 != 0:
		print(-1)
		exit()
	ans += abs((v1 + v2) // 2 - v1)
if ans % 2 == 0:
	print(ans // 2)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = [0] * 5
cb = [0] * 5
for i in range(len(a)):
	ca[a[i] - 1] += 1
	cb[b[i] - 1] += 1
c = 0
x = False
for i in range(5):
	if (ca[i] - cb[i]) % 2 == 1:
		x = True
	if ca[i] >= cb[i]:
		c += (ca[i] - cb[i]) // 2
	else:
		c += (cb[i] - ca[i]) // 2
if x:
	print(-1)
else:
	print(c // 2)


N = int(input())
map_a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
map_b = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for n in input().split():
	map_a[int(n)] += 1
for n in input().split():
	map_b[int(n)] += 1
diff = 0
sum_n = 0
for key in map_a:
	dff = map_a[key] - map_b[key]
	if dff % 2 != 0:
		diff = -1
		break
	diff += dff
	sum_n += abs(dff // 2)
if diff == 0:
	print(sum_n // 2)
else:
	print(-1)


import sys

def make_splits(group_a, group_b):
	r = group_a.copy()
	r = group_a + group_b
	ratings = sorted(r)
	target_a = []
	target_b = []
	for i in range(0, len(ratings), 2):
		if ratings[i] != ratings[i + 1]:
			print(-1)
			sys.exit(0)
		target_a.append(ratings[i])
		target_b.append(ratings[i + 1])
	return (target_a, target_a)

def find_lcs_dp(target_a, target_b, m, n):
	cache = [[None] * (n + 1) for i in range(m + 1)]
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				cache[i][j] = 0
			elif target_a[i - 1] == target_b[j - 1]:
				cache[i][j] = cache[i - 1][j - 1] + 1
			else:
				cache[i][j] = max(cache[i - 1][j], cache[i][j - 1])
	return cache[m][j]
ns = int(input().strip())
group_a = [int(i) for i in str(input()).split()]
group_b = [int(i) for i in str(input()).split()]
(target_a, target_b) = make_splits(group_a, group_b)
m = find_lcs_dp(sorted(group_a), target_a, len(target_a), len(target_b))
print(ns - m)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = {}
d = {}
for i in range(n):
	if a[i] in c:
		c[a[i]] += 1
	else:
		c[a[i]] = 1
for i in range(n):
	if b[i] in d:
		d[b[i]] += 1
	else:
		d[b[i]] = 1
e = 0
g = 0
h = 0
m = 0
o = 0
for i in c:
	if i in d:
		if c[i] == d[i]:
			continue
		else:
			if c[i] > d[i]:
				g = abs(c[i] - d[i])
			else:
				g = 0
			if g % 2 == 0:
				h += g // 2
			else:
				h = -1
				break
	else:
		g = c[i]
		if g % 2 == 0:
			e += g // 2
		else:
			e = -1
			break
for i in d:
	if i not in c:
		g = d[i]
		if g % 2 == 0:
			o += g // 2
		else:
			o = -1
if h == -1 or e == -1 or o == -1:
	e = -1
else:
	e = h + e
print(e)


import math

def main_function():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	hash_1 = [0 for i in range(6)]
	hash_2 = [0 for i in range(6)]
	counter = 0
	is_answer_found = False
	for i in range(n):
		hash_1[a[i]] += 1
		hash_2[b[i]] += 1
	for i in range(1, 6):
		if (hash_2[i] + hash_1[i]) % 2 != 0:
			is_answer_found = True
			print(-1)
			break
		counter += abs(hash_2[i] - (hash_2[i] + hash_1[i]) // 2)
	if not is_answer_found:
		print(counter // 2)
main_function()


import math
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = a + b
d = c.count(1)
e = c.count(2)
f = c.count(3)
g = c.count(4)
h = c.count(5)
i = 0
if d % 2 != 0 or e % 2 != 0 or f % 2 != 0 or (g % 2 != 0) or (h % 2 != 0):
	print(-1)
else:
	i = abs(d // 2 - a.count(1)) + abs(e // 2 - a.count(2)) + abs(f // 2 - a.count(3)) + abs(g // 2 - a.count(4)) + abs(h // 2 - a.count(5))
	print(i // 2)


from collections import Counter
N = int(input())
A = map(int, input().strip().split())
B = map(int, input().strip().split())
a = Counter(A)
b = Counter(B)
cnt = 0
aa = 0
bb = 0
flag = False
for i in range(1, 6):
	diff = a[i] - b[i]
	if diff % 2 == 1:
		flag = True
		break
	if diff > 0:
		aa += diff // 2
	else:
		bb += -diff // 2
if flag:
	print(-1)
elif aa == bb:
	print(aa)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, 6):
	if (a.count(i) + b.count(i)) % 2 != 0:
		print(-1)
		exit()
res = 0
for i in range(1, 6):
	res += max(0, (a.count(i) - b.count(i)) // 2)
print(res)


n = int(input())
classA = list(map(int, input().split()))
classB = list(map(int, input().split()))
a1 = classA.count(1)
b1 = classA.count(2)
c1 = classA.count(3)
d1 = classA.count(4)
e1 = classA.count(5)
a2 = classB.count(1)
b2 = classB.count(2)
c2 = classB.count(3)
d2 = classB.count(4)
e2 = classB.count(5)
z1 = abs(a1 - a2)
z2 = abs(b1 - b2)
z3 = abs(c1 - c2)
z4 = abs(d1 - d2)
z5 = abs(e1 - e2)
if z1 % 2 == 0 and z2 % 2 == 0 and (z3 % 2 == 0) and (z4 % 2 == 0) and (z5 % 2 == 0):
	C = (z1 + z2 + z3 + z4 + z5) // 2
	if C % 2 == 0:
		print(C // 2)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
d = {}
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
for i in b:
	if i not in d:
		d[i] = -1
	else:
		d[i] -= 1
ans = 0
for i in d:
	if d[i] % 2 == 1:
		ans = -1
if ans != -1:
	cnt = 0
	for i in d:
		cnt += abs(d[i])
	ans = cnt // 4
print(ans)


def mult_mat(M1, M2):
	a11 = M1[0][0] * M2[0][0] + M1[0][1] * M2[1][0]
	a12 = M1[0][0] * M2[0][1] + M1[0][1] * M2[1][1]
	a21 = M1[1][0] * M2[0][0] + M1[1][1] * M2[1][0]
	a22 = M1[1][0] * M2[0][1] + M1[1][1] * M2[1][1]
	r = [[a11, a12], [a21, a22]]
	return r

def binpow(a, n):
	rez = [[a[0][0], a[0][1]], [a[1][0], a[1][1]]]
	s = bin(n)[3:]
	for i in s:
		rez = mult_mat(rez, rez)
		if i == '1':
			rez = mult_mat(rez, a)
	return rez[0][0]

def main():
	QWE = 'river'
	INF = 10 ** 18 + 9
	EPS = 10 ** (-9)
	import sys, math, re, urllib.request
	n = int(input())
	a = [0] * 5
	b = [0] * 5
	c = [0] * 5
	for i in input().split(' ', n - 1):
		a[int(i) - 1] += 1
	for i in input().split(' ', n - 1):
		b[int(i) - 1] += 1
	rez = 0
	for i in range(5):
		c[i] = abs(a[i] - b[i])
		if c[i] % 2 == 1:
			print(-1)
			return 0
		rez += c[i]
	print(rez // 4)
main()


n = int(input())
a = []
(m, n) = [[int(x) for x in input().split()] for y in range(2)]
t = True
for x in range(1, 6):
	a += [abs(m.count(x) - n.count(x))]
	if (m.count(x) + n.count(x)) % 2 == 1:
		t = False
k = sum(a)
if t:
	print(k // 4)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
(x, y) = ([0] * 6, [0] * 6)
for i in range(n):
	x[l[i]] += 1
	y[d[i]] += 1
c = 0
f = 0
for i in range(1, 6):
	k = x[i] + y[i]
	if k % 2 == 1:
		f = 1
		break
	c = c + abs(k // 2 - x[i])
if f == 0:
	print(c // 2)
else:
	print(-1)


n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
(d1, d2, s1, s2) = (dict(), dict(), tuple(set(A)), tuple(set(B)))
for i in s1:
	d1[i] = A.count(i)
	if i not in s2:
		d2[i] = 0
for i in s2:
	d2[i] = B.count(i)
	if i not in s1:
		d1[i] = 0
N = 0
b = True
for i in d1:
	if (d1[i] + d2[i]) % 2 != 0:
		b = False
		break
	N += abs(d1[i] - d2[i])
if b:
	print(N // 4)
else:
	print(-1)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
if (a.count(1) + b.count(1)) % 2 or (a.count(2) + b.count(2)) % 2 or (a.count(3) + b.count(3)) % 2 or (a.count(4) + b.count(4)) % 2 or (a.count(5) + b.count(5)) % 2:
	print(-1)
else:
	print(round(((a.count(1) + b.count(1)) / 2 - min(a.count(1), b.count(1)) + (a.count(2) + b.count(2)) / 2 - min(a.count(2), b.count(2)) + (a.count(3) + b.count(3)) / 2 - min(a.count(3), b.count(3)) + (a.count(4) + b.count(4)) / 2 - min(a.count(4), b.count(4)) + (a.count(5) + b.count(5)) / 2 - min(a.count(5), b.count(5))) / 2))


import collections
n = int(input())
a = map(int, input().split())
b = map(int, input().split())
ac = collections.Counter(a)
bc = collections.Counter(b)
cnt = True
f = [0, 0]
for i in range(1, 6):
	na = int(ac[i])
	nb = int(bc[i])
	if (na + nb) % 2 == 0:
		if na > nb:
			f[0] += int((na - nb) / 2)
		else:
			f[1] += int((nb - na) / 2)
	else:
		cnt = False
		print('-1')
		break
if f[0] == f[1] and cnt:
	print(f[0])
elif cnt:
	print('-1')


n = int(input())
a = list(map(int, input().split()))
aa = [0 for i in range(6)]
for i in a:
	aa[i] += 1
b = list(map(int, input().split()))
bb = [0 for i in range(6)]
for i in b:
	bb[i] += 1
c = [aa[i] + bb[i] for i in range(6)]
for i in c:
	if i % 2 == 1:
		print(-1)
		exit()
ans = sum([abs(c[i] // 2 - aa[i]) for i in range(6)])
print(ans // 2)


n = int(input())
li1 = [int(x) for x in input().split()]
li2 = [int(x) for x in input().split()]
cnt = [0 for x in range(6)]
for i in li1:
	cnt[i] += 1
for i in li2:
	cnt[i] -= 1
for i in cnt:
	if i % 2 != 0:
		print(-1)
		break
else:
	ans = sum([abs(x) for x in cnt])
	print(ans // 4)


n = int(input())
arra = list(map(int, input().split()))
arrb = list(map(int, input().split()))
b = 0
for i in range(1, 6):
	if (arra.count(i) + arrb.count(i)) % 2 != 0:
		b = 1
		print(-1)
		break
if b == 0:
	used = []
	count = 0
	for i in range(n):
		if arra[i] not in arrb:
			used.append(arra[i])
		else:
			arrb.remove(arra[i])
	print(len(used) // 2)


_ = int(input())
vetor_A = list(map(int, input().split()))
vetor_B = list(map(int, input().split()))
table_T = [0 for i in range(6)]
table_A = [0 for i in range(6)]
table_B = [0 for i in range(6)]
for n in vetor_A:
	table_A[n] += 1
	table_T[n] += 1
for n in vetor_B:
	table_B[n] += 1
	table_T[n] += 1
flag = True
for num in table_T:
	if num % 2 == 1:
		flag = False
if flag:
	ans = 0
	for i in range(6):
		avg = table_T[i] // 2
		ans += abs(avg - table_A[i])
	print(ans // 2)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt_a = 6 * [0]
cnt_b = 6 * [0]
for i in range(6):
	cnt_a[i] = a.count(i)
	cnt_b[i] = b.count(i)
can = 1
need = 0
for i in range(1, 6):
	if cnt_a[i] + cnt_b[i] & 1:
		can = 0
		break
	else:
		tmp = (cnt_a[i] + cnt_b[i]) / 2 - cnt_a[i]
		need += tmp if tmp > 0 else 0
print(int(need) if can else -1)


import sys
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
l1 = [0] * 6
l2 = [0] * 6
for i in range(n):
	l1[A[i]] += 1
	l2[B[i]] += 1
flag = True
ans = 0
for i in range(1, 6):
	x = l1[i] + l2[i]
	if x % 2 != 0:
		flag = False
		break
	ans += abs(x // 2 - l1[i])
if flag:
	print(ans // 2)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0, 0, 0, 0, 0]
for i in a:
	c[i - 1] += 1
for j in b:
	c[j - 1] -= 1
s = 0
for i in c:
	if abs(i) % 2 == 0:
		s += abs(i)
	else:
		print(-1)
		exit()
x = s // 2
print(x // 2)


n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
count11 = 0
count22 = 0
count33 = 0
count44 = 0
count55 = 0
for i in range(0, n):
	if arr1[i] == 1:
		count1 += 1
	elif arr1[i] == 2:
		count2 += 1
	elif arr1[i] == 3:
		count3 += 1
	elif arr1[i] == 4:
		count4 += 1
	elif arr1[i] == 5:
		count5 += 1
	if arr2[i] == 1:
		count1 += 1
	elif arr2[i] == 2:
		count2 += 1
	elif arr2[i] == 3:
		count3 += 1
	elif arr2[i] == 4:
		count4 += 1
	elif arr2[i] == 5:
		count5 += 1
if count1 % 2 != 0 or count2 % 2 != 0 or count3 % 2 != 0 or (count4 % 2 != 0) or (count5 % 2 != 0):
	print(-1)
	exit()
for i in range(0, n):
	if arr1[i] == 1:
		count11 += 1
	elif arr1[i] == 2:
		count22 += 1
	elif arr1[i] == 3:
		count33 += 1
	elif arr1[i] == 4:
		count44 += 1
	elif arr1[i] == 5:
		count55 += 1
x = 0
if count11 != 0 and count11 > count1 // 2:
	x = x + count11 - count1 // 2
if count22 != 0 and count22 > count2 // 2:
	x = x + count22 - count2 // 2
if count33 != 0 and count33 > count3 // 2:
	x = x + count33 - count3 // 2
if count44 != 0 and count44 > count4 // 2:
	x = x + count44 - count4 // 2
if count55 != 0 and count55 > count5 // 2:
	x = x + count55 - count5 // 2
print(x)


from collections import Counter
(n, v, c1, c2) = (int(input()), 0, Counter(map(int, input().split())), Counter(map(int, input().split())))
for i in range(1, 6):
	x = c1[i] + c2[i]
	if (c1[i] + c2[i]) % 2:
		print(-1)
		exit()
	else:
		v += abs(c1[i] - c2[i]) // 2
print(v // 2)


(n, p, q) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
h1 = [0] * 5
c = 0
h2 = [] + h1
for i in p:
	h1[i - 1] += 1
for i in q:
	h2[i - 1] += 1
for i in range(5):
	if (h1[i] + h2[i]) % 2 == 1:
		print('-1')
		exit()
	else:
		c += abs(h1[i] - h2[i]) / 2
print(int(c / 2))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [0 for _ in range(6)]
res = 0
flag = False
for i in range(n):
	x[a[i]] += 1
	x[b[i]] -= 1
for c in x:
	if c % 2:
		print(-1)
		flag = True
		break
	res += abs(c) // 2
if not flag:
	print(res // 2)


import sys
import math
import bisect

def transform(A):
	B = [0] * 5
	for i in range(len(A)):
		B[A[i] - 1] += 1
	return B

def solve(A, B):
	n = len(A)
	A = transform(A)
	B = transform(B)
	for i in range(5):
		min_val = min(A[i], B[i])
		A[i] -= min_val
		B[i] -= min_val
	ans = 0
	for i in range(5):
		tmp = A[i] + B[i]
		if tmp % 2 == 1:
			return -1
		ans += tmp
	return ans // 4

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B)
	print(ans)
main()


n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
count = [0] * 5
for grade in a:
	count[grade - 1] += 1
for grade in b:
	count[grade - 1] -= 1
suma = 0
flag = True
for item in count:
	if item % 2 == 1:
		flag = False
		break
	else:
		suma += abs(item) // 2
if flag:
	print(suma // 2)
else:
	print(-1)


n = int(input())
cnt = [0] * 5
A = [int(i) - 1 for i in input().split()]
B = [int(i) - 1 for i in input().split()]
for i in A:
	cnt[i] += 1
for i in B:
	cnt[i] -= 1
res_4 = sum((abs(i) for i in cnt))
for i in cnt:
	if i % 2 == 1:
		print(-1)
		exit()
if res_4 % 4 != 0:
	print(-1)
else:
	print(res_4 // 4)


import sys

def make_gen(str):
	arr = str.split(' ')
	for item in arr:
		yield int(item)
n = int(input())
class_a = [0] * 5
class_b = [0] * 5
s = input()
s = make_gen(s)
for i in range(0, n):
	x = next(s)
	class_a[x - 1] += 1
s = input()
s = make_gen(s)
for i in range(0, n):
	x = next(s)
	class_b[x - 1] += 1
change1 = 0
change2 = 0
for i in range(0, 5):
	if (class_a[i] + class_b[i]) % 2 == 1:
		print(-1)
		sys.exit()
	med = (class_a[i] + class_b[i]) // 2
	change1 += abs(class_a[i] - med)
	change2 += abs(class_a[i] - med)
if change1 == change2:
	print(change1 // 2)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = [0, 0, 0, 0, 0]
cb = [0, 0, 0, 0, 0]
for i in a:
	ca[i - 1] += 1
for i in b:
	cb[i - 1] += 1
c = 0
for i in range(5):
	if (ca[i] + cb[i]) % 2 == 0:
		c += (max(ca[i], cb[i]) - min(ca[i], cb[i])) // 2
	else:
		print(-1)
		return
print(c // 2)


n = int(input())
p = list(map(int, input().split()))
ka = list(map(int, input().split()))
so = list(set(p))
po = list(set(ka))
tod = []
lol = []
sam = []
lil = []
loll = 0
tt = []
lkl = []
for item in so:
	tod.append(item)
for item in po:
	if item not in tod:
		tod.append(item)
for item in tod:
	lol.append(ka.count(item) + p.count(item))
for item in lol:
	if item % 2 == 0:
		pass
	else:
		loll = 1
		break
if loll == 1:
	print(-1)
else:
	lol = []
	for item in tod:
		sam.append(p.count(item))
		lol.append(ka.count(item))
	for x in range(len(sam)):
		if sam[x] == lol[x]:
			pass
		elif sam[x] > lol[x]:
			tt.append((sam[x] + lol[x]) // 2 - lol[x])
		else:
			lkl.append((sam[x] + lol[x]) // 2 - sam[x])
	if sum(tt) != sum(lkl):
		print(-1)
	else:
		print(sum(tt))


def sol():
	total = 0
	for i in range(1, 6):
		count1 = 0
		count2 = 0
		for j in range(n):
			if l1[j] == i:
				count1 += 1
			if l2[j] == i:
				count2 += 1
		if (count2 + count1) % 2 == 0:
			total += abs(count2 - (count1 + count2) // 2)
		else:
			return -2
	return total
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
print(sol() // 2)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [0] * 6
for i in a:
	cnt[i] += 1
for i in b:
	cnt[i] -= 1
su = 0
for i in cnt:
	if i % 2 != 0:
		print(-1)
		exit()
	if i > 0:
		su += i
print(su // 2)


from sys import stdin
n = int(stdin.readline().rstrip())
diff = [0, 0, 0, 0, 0]
for x in stdin.readline().rstrip().split(' '):
	diff[int(x) - 1] += 1
for x in stdin.readline().rstrip().split(' '):
	diff[int(x) - 1] -= 1
result = 0
for k in diff:
	if k % 2 == 1:
		print(-1)
		exit()
	elif k > 0:
		result += k
print(result // 2)


n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
ad = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
bd = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for a in al:
	ad[a] += 1
for b in bl:
	bd[b] += 1
flag = True
num = 0
for i in range(1, 6):
	cur = abs(ad[i] - bd[i])
	if abs(ad[i] - bd[i]) % 2 > 0:
		flag = False
		break
	num += cur
if flag:
	print(num // 4)
else:
	print(-1)


from sys import stdin, stdout
n = int(stdin.readline())
A = stdin.readline().rstrip().split()
A = [int(num) for num in A]
B = stdin.readline().rstrip().split()
B = [int(num) for num in B]
possible = True
totSwaps = 0
for i in range(1, 6):
	if (A.count(i) + B.count(i)) % 2 == 0:
		totSwaps += int((A.count(i) + B.count(i)) / 2) - min([A.count(i), B.count(i)])
	else:
		possible = False
		break
if not possible:
	print(-1)
else:
	print(int(totSwaps / 2))


n = int(input())
pp = input().split()
mm = input().split()
p = [0] * 5
m = [0] * 5
t = 0
l = 0
for i in range(0, n):
	p[int(pp[i]) - 1] += 1
	m[int(mm[i]) - 1] += 1
for i in range(0, 5):
	if abs(p[i] - m[i]) % 2 != 0:
		l += 1
		break
	else:
		t = t + abs(p[i] - m[i]) // 2
if l != 0:
	print('-1')
else:
	print(t // 2)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = [int(y) for y in input().split()]
l = l1 + l2
l = sorted(l)
an = []
counting = [0] * 250
for i in l:
	counting[i] = counting[i] + 1
for i in counting:
	if i % 2 != 0:
		print(-1)
		break
else:
	for i in range(0, len(l), 2):
		an.append(l[i])
		an = sorted(an)
		l1 = sorted(l1)
	for i in range(n):
		if an[i] in l1:
			l1.remove(an[i])
	print(len(l1))


import sys
import re
input = lambda : sys.stdin.readline()
import functools

@functools.lru_cache(maxsize=10000)
def Main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = 0
	for i in range(1, 6):
		f = A.count(i)
		s = B.count(i)
		if (f + s) % 2 != 0:
			print(-1)
			return 0
		ans += abs(f - s) // 2
	print(ans // 2)
Main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = [0] * 6
for i in a:
	q[i] += 1
for i in b:
	q[i] += 1
f = True
for i in q:
	if i % 2 != 0:
		f = False
if not f:
	print(-1)
else:
	for i in range(6):
		q[i] //= 2
	aa = [0] * 6
	bb = [0] * 6
	for i in a:
		aa[i] += 1
	for i in b:
		bb[i] += 1
	ans = 0
	for i in range(6):
		ans += abs(q[i] - aa[i])
	print(ans // 2)


def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return input().split()

def S():
	return input()

def check(li1, li2):
	result = 0
	for i in range(5):
		result += (max(li1[i], li2[i]) - min(li1[i], li2[i])) / 2
		if (li1[i] + li2[i]) % 2 != 0:
			print(-1)
			return
	print(int(result / 2))
	return
li1 = [0, 0, 0, 0, 0]
li2 = [0, 0, 0, 0, 0]
n = II()
ll1 = LI()
ll2 = LI()
for i in range(n):
	li1[ll1[i] - 1] += 1
	li2[ll2[i] - 1] += 1
check(li1, li2)


n = int(input())
a = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
b = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for i in map(int, input().split()):
	a[i] += 1
for i in map(int, input().split()):
	b[i] += 1
a1 = 0
a2 = 0
for i in range(1, 6):
	q = a[i] - b[i]
	if q % 2:
		print(-1)
		exit()
	if q > 0:
		a1 += q
	else:
		a2 += q
print(a1 // 2)


n = int(input())
a = input().split()
b = input().split()
c1 = [0, 0, 0, 0, 0, 0]
c2 = [0, 0, 0, 0, 0, 0]
ans = 0
for i in a:
	c1[int(i)] += 1
for i in b:
	c2[int(i)] += 1
for i in range(6):
	if (c1[i] + c2[i]) % 2 == 1:
		print('-1')
		exit(0)
	else:
		ans += abs(c1[i] - c2[i])
print(ans // 4)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
ans = 0
am = [0] * 5
bm = [0] * 5
for i in a:
	am[i - 1] += 1
for i in b:
	bm[i - 1] += 1
for i in range(5):
	if am[i] != bm[i]:
		if (am[i] - bm[i]) % 2 == 0:
			ans += abs(am[i] - bm[i]) // 2
		else:
			ans = -1
			break
print(ans // 2)


class school:
	n = 0
	A = []
	B = []
	count = 0
	f = 0

	def __init__(self, n, A, B):
		self.n = n
		for i in range(n):
			self.A.append(int(A.split(' ')[i]))
			self.B.append(int(B.split(' ')[i]))
		self.calc()

	def calc(self):
		for i in range(1, 6):
			x = self.A.count(i)
			y = self.B.count(i)
			z = x + y
			if z % 2 == 0:
				self.count += abs(x - y) / 2
			else:
				print(-1)
				exit()
		if self.f == 1:
			print(-1)
		else:
			print(int(self.count / 2))

def Main():
	n = int(input(''))
	A = input('')
	B = input('')
	stu = school(n, A, B)
Main()


def solve(n, arr1, arr2):
	d = {}
	for i in arr1:
		if d.get(i) == None:
			d[i] = False
	tot = 0
	for i in range(n):
		el = arr1[i]
		if d[el]:
			continue
		count1 = arr1.count(el)
		count2 = arr2.count(el)
		count = count1 + count2
		if count % 2:
			return -1
		if count1 > count2:
			tot += count1 - count // 2
		d[el] = True
	for i in range(n):
		el = arr2[i]
		count1 = arr1.count(el)
		count2 = arr2.count(el)
		count = count1 + count2
		if count % 2:
			return -1
	return tot

def main():
	n = int(input())
	arr1 = list(map(int, input().split(' ')))
	arr2 = list(map(int, input().split(' ')))
	print(solve(n, arr1, arr2))
main()


x = input()
s_1 = input()
s_2 = input()
s_1 = s_1.split(' ')
s_2 = s_2.split(' ')
first = []
second = []
i = 0
answer = 0
k = 0
for i in range(1, 6):
	first.append(0)
	second.append(0)
i = 0
for i in range(0, len(s_1)):
	first[int(s_1[i]) - 1] += 1
j = 0
for j in range(0, len(s_2)):
	second[int(s_2[j]) - 1] += 1
for i in range(0, 5):
	answer += max(first[i], second[i]) - (first[i] + second[i]) // 2
	if (first[i] + second[i]) % 2 != 0:
		print(-1)
		exit(0)
print(answer // 2)


n = int(input())
A = [0] * 5
B = [0] * 5
for a in map(int, input().split()):
	A[a - 1] += 1
for a in map(int, input().split()):
	B[a - 1] += 1
if any([(x + y) % 2 != 0 for (x, y) in zip(A, B)]):
	print(-1)
else:
	print(sum([abs(x - y) // 2 for (x, y) in zip(A, B)]) // 2)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
arr_A = [0 for i in range(5)]
arr_B = [0 for i in range(5)]
for i in range(n):
	arr_A[A[i] - 1] += 1
	arr_B[B[i] - 1] += 1
down = 0
up = 0
stop = 0
for (i, j) in zip(arr_A, arr_B):
	sum = i + j
	if sum % 2 != 0:
		print(-1)
		stop = 1
		break
	if i > j:
		down += i - sum / 2
	elif j > i:
		up += j - sum / 2
if stop == 0:
	if up == down:
		print(int(up))
	else:
		print(-1)


n = int(input())
g1 = list(map(int, input().split()))
g2 = list(map(int, input().split()))
c1 = {i: 0 for i in range(1, 6)}
c2 = {i: 0 for i in range(1, 6)}
for i in range(n):
	c1[g1[i]] += 1
	c2[g2[i]] += 1
if all(((c1[i] - c2[i]) % 2 == 0 for i in range(1, 6))) and sum((c1[i] - c2[i] for i in range(1, 6))) == 0:
	print(sum((abs(c1[i] - c2[i]) for i in range(1, 6))) // 4)
else:
	print(-1)