#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T LCM(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
T expo(T base, T e, T mod) {
  T res = 1;
  while (e > 0) {
    if (e & 1) res = res * base % mod;
    base = base * base % mod;
    e >>= 1;
  }
  return res;
}
template <typename T, typename second>
T expo(T b, second e) {
  if (e <= 1) return e == 0 ? 1 : b;
  return (e & 1) == 0 ? expo((b * b), e >> 1) : (b * expo((b * b), e >> 1));
}
template <typename T, typename second>
T modinv(T a, second mod) {
  return expo(a, mod - 2, mod);
}
template <class T, class second>
std::ostream &operator<<(std::ostream &os, const std::pair<T, second> &t) {
  os << "(" << t.first << ", " << t.second << ")";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &t) {
  os << "[";
  for (__typeof(t.begin()) it = t.begin(); it != t.end(); it++) {
    if (it != t.begin()) os << ", ";
    os << *it;
  }
  os << "]";
  return os;
}
const int MAXN = 1e5 + 100;
int n;
int don;
vector<int> arr;
vector<int> B;
bool xorlele;
bool is_fine(int yall) {
  vector<int> cpy = arr;
  sort(cpy.begin(), cpy.end());
  vector<int> C2 = B;
  sort(C2.begin(), C2.end());
  bool temp = true;
  int idx = -1;
  for (int i = 0; i < cpy.size(); i++) {
    if (cpy[i] != C2[i]) {
      idx = i;
      temp = false;
      don = cpy[i];
      break;
    }
  }
  if (temp) return true;
  cpy[idx] = yall;
  sort(cpy.begin(), cpy.end());
  for (int i = 0; i < cpy.size(); i++) {
    if (cpy[i] != C2[i]) return false;
  }
  xorlele = true;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  int yall = 0;
  cin >> n;
  arr.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    yall ^= arr[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> B[i];
  }
  bool ok = false;
  int res = -1;
  if (is_fine(yall)) {
    res = 0;
    bool temp = true;
    for (int i = 0; i < n; i++) {
      if (arr[i] != B[i]) {
        temp = false;
        break;
      }
    }
    if (temp) {
      cout << 0 << endl;
      return 0;
    }
    res = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] != B[i]) {
        res++;
      }
    }
    if (!xorlele) res++;
  } else {
    ok = false;
    res = -1;
  }
  cout << res << '\n';
  return 0;
}
