#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  char c = getchar();
  int p = 1;
  x = 0;
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ '0');
    c = getchar();
  }
  x *= p;
}
const int maxn = 100050;
int a[maxn], n, b[maxn], ta[maxn], tb[maxn], ans;
bool flag;
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) {
    read(a[i]);
    a[n + 1] ^= a[i];
  }
  for (register int i = 1; i <= n; ++i) {
    read(b[i]);
    b[n + 1] ^= b[i];
  }
  memset(ta, -1, sizeof(ta)), memset(tb, -1, sizeof(tb));
  for (register int i = 1; i <= n + 1; ++i) {
    ta[i] = a[i];
  }
  for (register int j = 1; j <= n + 1; ++j) {
    tb[j] = b[j];
  }
  sort(ta + 1, ta + 1 + n + 1), sort(tb + 1, tb + 1 + n + 1);
  for (register int i = 1; i <= n + 1; ++i) {
    if (ta[i] != tb[i]) {
      puts("-1");
      return 0;
    }
  }
  for (register int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) {
      ++ans;
      if (b[i] == a[n + 1]) flag = 1;
    }
  }
  if (ans == 0) {
    puts("0");
    return 0;
  }
  for (register int i = 1; i <= n; ++i) {
    ta[i] = a[i], tb[i] = b[i];
  }
  bool flag2 = 0;
  sort(ta + 1, ta + 1 + n), sort(tb + 1, tb + 1 + n);
  for (register int i = 1; i <= n; ++i) {
    if (ta[i] != tb[i]) flag2 = 1;
  }
  if (flag && flag2)
    printf("%d\n", ans);
  else
    printf("%d\n", ans + 1);
  return 0;
}
