#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  int a_sum = 0;
  for (int i = 0; i < n; ++i) {
    a_sum ^= a[i];
  }
  vector<int> c, d;
  unordered_multimap<int, int> d_map;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      continue;
    }
    c.push_back(a[i]);
    d.push_back(b[i]);
    d_map.emplace(d.back(), d.size() - 1);
  }
  const int m = c.size();
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  int answer = 0;
  while (d_map.find(a_sum) != d_map.end()) {
    const auto it = d_map.find(a_sum);
    const int t = c[it->second];
    c[it->second] = a_sum;
    a_sum = t;
    ++answer;
    d_map.erase(it);
  }
  for (int i = 0; i < m; ++i) {
    if (c[i] == d[i]) {
      continue;
    }
    ++answer;
    swap(a_sum, c[i]);
    while (d_map.find(a_sum) != d_map.end()) {
      const auto it = d_map.find(a_sum);
      const int t = c[it->second];
      c[it->second] = a_sum;
      a_sum = t;
      ++answer;
      d_map.erase(it);
    }
  }
  if (!d_map.empty()) {
    answer = -1;
  }
  cout << answer << endl;
  return 0;
}
