#include <bits/stdc++.h>
using namespace std;
int getint() {
  char ch = getchar();
  int f = 1, x = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
const int N = 100100;
int n;
int a[N], a2[N];
int b[N], b2[N];
void init() {
  n = getint();
  for (int i = 1; i <= n; i++) {
    a[i] = a2[i] = getint();
    a[0] ^= a[i];
    a2[0] ^= a[i];
  }
  for (int i = 1; i <= n; i++) {
    b[i] = b2[i] = getint();
    b[0] ^= b[i];
    b2[0] ^= b[i];
  }
  sort(a2, a2 + 1 + n);
  sort(b2, b2 + 1 + n);
}
int main() {
  init();
  bool flag = false;
  for (int i = 0; i <= n; i++) {
    if (a2[i] != b2[i]) {
      flag = true;
      break;
    }
  }
  if (flag) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a[i] != b[i];
  }
  ans += (ans != 0) && (a[0] == b[0]);
  printf("%d\n", ans);
  return 0;
}
