#include <bits/stdc++.h>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
int A[100010], B[100010];
std::vector<int> a, b;
int main() {
  int n = gi(), XOR = 0, xorb = 0;
  for (int i = 1; i <= n; ++i) A[i] = gi(), XOR ^= A[i], a.push_back(A[i]);
  for (int i = 1; i <= n; ++i) B[i] = gi(), xorb ^= B[i], b.push_back(B[i]);
  a.push_back(XOR), b.push_back(xorb);
  std::sort(a.begin(), a.end());
  std::sort(b.begin(), b.end());
  if (a != b) return puts("-1"), 0;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) cnt += A[i] != B[i];
  if (!cnt)
    puts("0");
  else
    printf("%d\n", cnt + (XOR == xorb));
  return 0;
}
