#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

using namespace std;

class C {
public:
	long long bl;
	int id;
	C(int i, long long v) {
		id = i;
		bl = v;
	}
	bool operator>(C &rhs) {
		if (this->bl > rhs.bl) {
			return true;
		}
		else if (this->bl == rhs.bl) {
			return this->id > rhs.id;
		}
		return false;
	}
	bool operator<(C &rhs) {
		if (this->bl < rhs.bl) {
			return true;
		}
		else if (this->bl == rhs.bl) {
			return this->id < rhs.id;
		}
		return false;
	}
};

int main() {
	int n;
	vector<long long> a, b, A, B;
	cin >> n;
	a.resize(n);
	A.resize(n + 1);
	b.resize(n);
	B.resize(n + 1);
	long long x = 0, xx = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x ^= a[i];
		A[i] = a[i];
	}
	A[n] = x;
	a.push_back(x);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		xx ^= b[i];
		B[i] = b[i];
	}
	B[n] = xx;
	b.push_back(xx);
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	bool o = false;
	for (int i = 0; i < n + 1; i++) {
		if (A[i] != B[i]) {
			o = true;
		}
	}
	if (o) {
		cout << -1 << endl;
		return 0;
	}
	vector<C> aa, bb;
	for (int i = 0; i < n + 1; i++) {
		C hoge(i, a[i]), poyo(i, b[i]);
		aa.push_back(hoge);
		bb.push_back(poyo);
	}
	sort(aa.begin(), aa.end());
	sort(bb.begin(), bb.end());
	int ans = 0;
	for (int i = 0; i < n + 1; i++) {
		if (aa[i].id != bb[i].id) {
				ans++;
		}
	}
	cout << ans << endl;
//	cin >> n;
	return 0;
}
