#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
int A[N], B[N], cnt = 0;
map<int, vector<int>> pos;
void maintain(int x) {
  if (!pos.count(x)) return;
  while (!pos[x].empty()) {
    int p = pos[x].back();
    if (A[p] == B[p])
      pos[x].pop_back();
    else
      break;
  }
  if (pos[x].empty()) pos.erase(x);
}
void doswap(int i) {
  ++cnt;
  swap(A[i], A[n]);
  maintain(A[i]);
  maintain(A[n]);
}
int main() {
  printf("-1\n");
  return 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    A[n] ^= A[i];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &B[i]);
    B[n] ^= B[i];
    pos[B[i]].push_back(i);
  }
  int iter = 1e6;
  while (!pos.empty()) {
    if (--iter == 0) {
      cnt = -1;
      break;
    }
    maintain(A[n]);
    if (pos.count(A[n])) {
      doswap(pos[A[n]].back());
    } else {
      int x = pos.begin()->first;
      maintain(x);
      if (pos.count(x)) doswap(pos[x].back());
    }
  }
  printf("%d\n", cnt);
  return 0;
}
