#include <bits/stdc++.h>
using namespace std;
int xorv(const vector<int>& v) {
  int res = 0;
  for (auto e : v) {
    res ^= e;
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> b[i];
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  int xa = xorv(a);
  int xb = xorv(b);
  multiset<int> as(a.begin(), a.end());
  multiset<int> bs(b.begin(), b.end());
  bool isneg = (as != bs);
  as.insert(xa);
  bs.insert(xb);
  if (as != bs)
    cout << -1 << endl;
  else {
    int res = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) res++;
    }
    if (isneg) res--;
    cout << res << endl;
  }
  return 0;
}
