#include <bits/stdc++.h>
using namespace std;
map<unsigned int, unsigned int> A, B, brakuje;
vector<unsigned int> a, b;
int N;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    unsigned int x;
    scanf("%u", &x);
    A[x]++;
    a.push_back(x);
  }
  for (int i = 0; i < N; ++i) {
    unsigned int x;
    scanf("%u", &x);
    B[x]++;
    b.push_back(x);
  }
  unsigned int XORA = 0;
  for (map<unsigned int, unsigned int>::iterator it = A.begin(); it != A.end();
       ++it) {
    for (int i = 0; i < it->second; ++i) XORA = XORA ^ it->first;
  }
  unsigned int suma_braku = 0;
  bool niedasie = false;
  unsigned int czego_brakuje = -1;
  for (map<unsigned int, unsigned int>::iterator bit = B.begin();
       bit != B.end(); ++bit) {
    map<unsigned int, unsigned int>::iterator ait = A.find(bit->first);
    if (ait == A.end()) {
      brakuje.insert(make_pair(bit->first, bit->second));
      suma_braku += bit->second;
      czego_brakuje = bit->first;
    } else {
      if (bit->second > ait->second) {
        brakuje.insert(make_pair(bit->first, bit->second - ait->second));
        suma_braku += bit->second - ait->second;
        czego_brakuje = bit->first;
      } else if (ait->second > bit->second) {
        niedasie = true;
      }
    }
  }
  if (suma_braku > 1) niedasie = true;
  if (suma_braku == 1 && czego_brakuje != XORA) niedasie = true;
  if (niedasie) {
    printf("-1\n");
  } else {
    unsigned int res = 0;
    for (int i = 0; i < N; ++i) {
      if (a[i] != b[i]) res++;
    }
    if (suma_braku == 0 && res != 0) res++;
    printf("%u\n", res);
  }
  return 0;
}
