#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int xa = 0, xb = 0;
  multiset<int> s1, s2;
  int neq = 0;
  for (int i = 0; i < n; i++) cin >> a[i], xa ^= a[i], s1.insert(a[i]);
  for (int i = 0; i < n; i++) {
    cin >> b[i], xb ^= b[i], s2.insert(b[i]);
    if (b[i] != a[i]) neq++;
  }
  if (s1 == s2 && xa == xb && neq > 0 && s1.find(xa) == s1.end()) neq++;
  s1.insert(xa);
  s2.insert(xb);
  if (s1 != s2) neq = -1;
  cout << neq << '\n';
  return 0;
}
