#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> as(n);
  int s = 0;
  for (auto& a : as) {
    cin >> a;
    s ^= a;
  }
  vector<int> bs(n);
  for (auto& b : bs) {
    cin >> b;
  }
  multiset<int> ss(as.begin(), as.end());
  ss.insert(s);
  for (auto& b : bs) {
    auto it = ss.find(b);
    if (it == ss.end()) {
      cout << -1 << endl;
      return 0;
    }
    ss.erase(it);
  }
  int diff = 0, t = 0;
  for (int i = 0; i < n; i++) {
    if (as[i] != bs[i]) {
      diff++;
    }
    t ^= bs[i];
  }
  if (diff > 0 && s == t) diff++;
  cout << diff << endl;
  return 0;
}
