#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n, arr[100005], target[100005];
map<int, int> cnt1, cnt2;
vector<int> v1, v2;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int xorval = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    xorval ^= arr[i];
  }
  bool z = false;
  for (int i = 1; i <= n; i++) z |= (arr[i] == xorval);
  for (int i = 1; i <= n; i++) {
    cin >> target[i];
    if (arr[i] != target[i]) {
      v1.push_back(arr[i]);
      v2.push_back(target[i]);
      cnt1[arr[i]]++;
      cnt2[target[i]]++;
    }
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (v1.empty()) {
    cout << "0";
    return 0;
  }
  if (v1 == v2) {
    cout << (int)v1.size() + (z);
    return 0;
  }
  if (cnt2[xorval] == cnt1[xorval] + 1)
    cout << (int)v1.size();
  else
    cout << "-1";
  return 0;
}
