#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, P = 998244353;
inline int read() {
  int x = 0, f = 0, c = getchar();
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
}
int n, i, a[N], b[N], ct;
;
int main() {
  n = read();
  for (i = 1; i <= n; i++) a[i] = read(), a[n + 1] ^= a[i];
  for (i = 1; i <= n; i++) {
    b[i] = read(), b[n + 1] ^= b[i];
    ct += a[i] != b[i];
  }
  if (ct) ct += a[n + 1] == b[n + 1];
  sort(a + 1, a + n + 2);
  sort(b + 1, b + n + 2);
  for (i = 1; i <= n; i++)
    if (a[i] != b[i]) {
      puts("-1");
      return 0;
    }
  printf("%d\n", ct);
  return 0;
}
