#include <bits/stdc++.h>
int n, m;
int a[100010], b[100010];
int c[100010], d[100010];
int main(void) {
  int i;
  int answer = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]), a[0] ^= a[i];
  for (i = 1; i <= n; ++i) scanf("%d", &b[i]), b[0] ^= b[i];
  for (i = 1; i <= n; ++i)
    if (a[i] != b[i]) ++answer, c[++m] = a[i], d[m] = b[i];
  if (!answer) return puts("0"), 0;
  c[0] = a[0];
  d[0] = b[0];
  std::sort(c + 1, c + 1 + m);
  std::sort(d + 1, d + 1 + m);
  for (i = 1; i <= m; ++i)
    if (c[i] != d[i]) goto next;
  ++answer;
next:;
  std::sort(c, c + 1 + m);
  std::sort(d, d + 1 + m);
  for (i = 0; i <= m; ++i)
    if (c[i] != d[i]) return puts("-1"), 0;
  printf("%d\n", answer);
  return 0;
}
