#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, int> ii;

int MOD = 1e9 + 7;
int INF = 1e9;
// ll INF = 1e18;

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n;
vector<int> a, b;

int check(vector<int> x, vector<int> y){
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	for(int i=0;i<x.size();i++) if(x[i] - y[i]) return 0;
	return 1;
}

int solve(){
	cin >> n;
	a.resize(n);
	int sum = 0; for(int i=0;i<n;i++) cin >> a[i], sum ^= a[i];
	a.push_back(sum);
	b.resize(n);
	sum = 0; for(int i=0;i<n;i++) cin >> b[i], sum ^= b[i];
	b.push_back(sum);
	if(!check(a, b)) return cout << -1 << endl, 0;
	int cnt = 0;
	for(int i=0;i<n;i++) cnt += a[i] != b[i];
	cout << (cnt + (cnt > 0 && a[n] == b[n])) << endl;
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	// int t; cin >> t; while(t--)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}
