#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int P = 1e9 + 7;
const int inf = 1e9;
const long long Inf = 1e15;
inline int IN() {
  char ch = getchar();
  int x = 0, f = 0;
  while (ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - 48;
    ch = getchar();
  }
  return f ? (-x) : x;
}
inline int Pow(int x, int y, int p) {
  int an = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) an = (long long)an * x % p;
  return an;
}
void renew(int &x, int y) {
  x += y;
  if (x < 0)
    x += P;
  else if (x >= P)
    x -= P;
}
void setIO(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
template <typename T>
inline void chkmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <typename T>
inline void chkmax(T &a, const T &b) {
  if (a < b) a = b;
}
int n, a[N], b[N], pos[N], tot, X;
map<int, int> A, B;
int Cnt(int x) {
  if (B.find(x) == B.end()) return 0;
  return B[x];
}
int main() {
  scanf("%d", &n);
  for (int i = (int)1; i <= (int)n; i++) {
    scanf("%d", a + i);
    X ^= a[i];
    A[a[i]]++;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    scanf("%d", b + i);
    B[b[i]]++;
  }
  int flag = 1;
  for (int i = (int)1; i <= (int)n; i++)
    if (a[i] != b[i]) flag = 0;
  if (flag) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = (int)1; i <= (int)n; i++)
    if (a[i] != b[i]) pos[++tot] = i;
  A[X]++;
  int ok = -1;
  for (auto x : A)
    if (Cnt(x.first) + 1 == x.second) {
      ok = x.first;
      break;
    }
  if (ok == -1) {
    cout << -1 << endl;
    assert(0);
    return 0;
  }
  int oke = 1;
  for (auto x : A)
    if (x.first != ok && Cnt(x.first) != x.second) {
      oke = -1;
      break;
    }
  if (oke == -1) {
    cout << -1 << endl;
    assert(0);
    return 0;
  }
  if (ok == X) tot++;
  printf("%d\n", tot);
  return 0;
}
