#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
int N;
constexpr int Nmax = 100000;
map<lint, int> a;
lint xor_ = 0;
lint as[Nmax], bs[Nmax];
void No() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  cin >> N;
  for (int i = (0); i < (N); i++) {
    cin >> as[i];
    a[as[i]]++;
    xor_ ^= as[i];
  }
  int ans = 0;
  for (int i = (0); i < (N); i++) {
    cin >> bs[i];
    if (bs[i] == as[i]) {
      a[bs[i]]--;
    } else {
      if (a[bs[i]]) {
        a[bs[i]]--;
        ans += 1;
      } else if (xor_ == bs[i]) {
        xor_ = -1;
        ans += 1;
      } else
        No();
    }
  }
  if (ans == 0)
    cout << 0 << endl;
  else
    cout << ans + (xor_ != -1) << endl;
}
