#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int read(int &n) {
  char ch = ' ';
  int q = 0, w = 1;
  for (; (ch != '-') && ((ch < '0') || (ch > '9')); ch = getchar())
    ;
  if (ch == '-') w = -1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48;
  n = q * w;
  return n;
}
int m, n, m1, ans;
int a[N], b[N];
int main() {
  int q, w;
  read(n);
  q = 0;
  for (register int i = 1; i <= n; ++i) q = q ^ read(a[i]);
  for (register int i = 1; i <= n; ++i) ans += (a[i] != read(b[i]));
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  ++ans;
  for (register int i = 1; i <= n; ++i)
    if (a[i] != b[i]) {
      if (b[i] == q) {
        --ans;
        break;
      } else
        return printf("-1\n"), 0;
    }
  printf("%d\n", ans);
  return 0;
}
