#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn], b[maxn], n, ans;
multiset<int> s;
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &a[i]);
    a[n + 1] ^= a[i];
  }
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &b[i]);
    b[n + 1] ^= b[i];
  }
  n++;
  for (int i = (1); i <= (n); i++) s.insert(a[i]);
  for (int i = (1); i <= (n); i++) {
    if (s.find(b[i]) == s.end()) return puts("-1"), 0;
    s.erase(s.find(b[i]));
  }
  for (int i = (1); i <= (n - 1); i++)
    if (a[i] != b[i]) ans++;
  if (ans && a[n] == b[n]) ans++;
  printf("%d\n", ans);
  return 0;
}
