#include <bits/stdc++.h>
int cmp(const void *a, const void *b) {
  return *(long long *)a - *(long long *)b;
}
long long a[100000], b[100000], c[100001], d[100001], p, q, ans, r;
int main(int argc, char const *argv[]) {
  long n, i;
  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    c[i] = a[i];
    p = p ^ a[i];
  }
  c[i] = p;
  for (i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    d[i] = b[i];
    q = q ^ b[i];
  }
  d[i] = q;
  qsort(c, n + 1, sizeof(long long), cmp);
  qsort(d, n + 1, sizeof(long long), cmp);
  for (i = 0; i <= n; i++) {
    if (c[i] != d[i]) {
      printf("-1\n");
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    if (a[i] != b[i]) ans++;
  }
  if (p == q) ans++;
  printf("%lld\n", ans);
  return 0;
}
