#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a, b;
unordered_map<int, int> cntA;
int main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  int foo = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    foo ^= a[i];
    ++cntA[a[i]];
  }
  bool used = false;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    if (cntA[b[i]] > 0) {
      --cntA[b[i]];
    } else if (!used && b[i] == foo) {
      used = true;
    } else {
      cout << -1;
      return 0;
    }
    cnt += (a[i] == b[i] ? 0 : 1);
  }
  if (used) {
    cout << (cnt == 1 ? 1 : cnt + 1);
  } else {
    cout << (cnt == 0 ? 0 : cnt + 1);
  }
  return 0;
}
