#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); ++i) cin >> a[i];
  vector<int> b(n);
  for (int i = 0; i < (int)(n); ++i) cin >> b[i];
  int sa = 0;
  int sb = 0;
  for (int i = 0; i < (int)(n); ++i) {
    sa ^= a[i];
    sb ^= b[i];
  }
  a.push_back(sa);
  b.push_back(sb);
  n++;
  map<int, int> mpa, mpb;
  for (int i = 0; i < (int)(n); ++i) {
    mpa[a[i]]++;
    mpb[b[i]]++;
  }
  for (auto x : mpa) {
    if (x.second != mpb[x.first]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int c = 0;
  map<int, multiset<int> > mp;
  for (int i = 0; i < (int)(n - 1); ++i) {
    if (a[i] != b[i]) {
      c++;
      mp[b[i]].insert(a[i]);
    }
  }
  if (c == 0) {
    cout << 0 << endl;
  } else {
    int p = sa;
    int res = 0;
    if (sa == sb) {
      cout << c + 1 << endl;
    } else {
      cout << c << endl;
    }
  }
  return 0;
}
