#include <bits/stdc++.h>
#pragma GCC optimize("3", "inline", "Ofast")
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
  x *= f;
}
int n, a[100005], b[100005];
map<int, int> cnt;
inline void Setfile(string Str = "") {
  if (Str == "") return;
  freopen((Str + ".in").c_str(), "r", stdin);
  freopen((Str + ".out").c_str(), "w", stdout);
}
int main() {
  Setfile();
  read(n);
  int ans = 0, flg = 1;
  for (int i = 1; i <= n; ++i) read(a[i]), ans ^= a[i], cnt[a[i]]++;
  cnt[ans]++;
  for (int i = 1; i <= n; ++i)
    read(b[i]), cnt[b[i]]--, flg &= (ans != b[i] && a[i] != b[i]);
  for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); ++it)
    if (it->second < 0) return 0 * puts("-1");
  int res = 0;
  for (int i = 1; i <= n; ++i) res += a[i] != b[i];
  printf("%d\n", res);
}
