#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {
  fin >> pr.first >> pr.second;
  return fin;
}
template <class T0, class T1, class T2>
inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {
  fin >> get<0>(t) >> get<1>(t) >> get<2>(t);
  return fin;
}
template <class T>
inline istream& operator>>(istream& fin, vector<T>& a) {
  for (auto& u : a) fin >> u;
  return fin;
}
template <class T, size_t n>
inline istream& operator>>(istream& fin, array<T, n>& a) {
  for (auto& u : a) fin >> u;
  return fin;
}
template <class FwdIter>
inline auto dump(FwdIter first, FwdIter last, const char* dlm = " ") -> void {
  copy(first, last,
       ostream_iterator<typename iterator_traits<FwdIter>::value_type>(cout,
                                                                       dlm));
}
template <typename T>
vector<T>& operator--(vector<T>& a) {
  for (auto& i : a) --i;
  return a;
}
int argc016_d() {
  size_t n;
  cin >> n;
  vector<uint32_t> a(n), b(n);
  cin >> a >> b;
  {
    uint32_t x = 0;
    for (const auto i : a) x ^= i;
    a.push_back(x);
  }
  {
    uint32_t x = 0;
    for (const auto i : b) x ^= i;
    b.push_back(x);
  }
  map<uint32_t, size_t> cnt;
  for (const auto i : a) ++cnt[i];
  for (const auto i : b) --cnt[i];
  for (const auto& pr : cnt)
    if (pr.second) return -1;
  size_t k = 0;
  for (size_t i = 0; i < n + 1; ++i) k += a[i] != b[i];
  ;
  ;
  ;
  if (!k) return 0;
  return a.back() == b.back() ? k + 1 : k - 1;
}
int main(const int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << argc016_d();
  return EXIT_SUCCESS;
}
