#include <bits/stdc++.h>
using namespace std;
int a[100500], b[100500];
int mid[100500], mid2[100500];
int main()
{
	int n = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i), a[0] ^= a[i];
	for(int i = 1; i <= n; i++) scanf("%d", b + i), b[0] ^= b[i];
	for(int i = 0; i <= n; i++) mid[i] = a[i], mid2[i] = b[i];
	sort(mid, mid + n + 1), sort(mid2, mid2 + n + 1);
	for(int i = 0; i <= n; i++)
		if(mid[i] != mid2[i])
		{
			puts("-1");
			return 0;
		}
	int p = 0, tot = 0;
	for(int i = 1; i <= n; i++)
		if(a[i] != b[i]) tot++;
	if(a[i] == b[i]) cout << tot + 1 << endl;
	else cout << tot << endl;
	return 0;
}