#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
using ll = long long;
using R = long double;
const R EPS = 1e-9L;
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R sq(R x) { return sqrt(max(x, 0.0L)); }
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int n;
int a[100010], b[100010], axor = 0, bxor = 0;
bool check() {
  vector<int> ca, cb;
  for (int i = int(0); i < int(n); ++i) ca.push_back(a[i]);
  for (int i = int(0); i < int(n); ++i) cb.push_back(b[i]);
  sort(begin(ca), end(ca));
  sort(begin(cb), end(cb));
  for (int i = int(0); i < int(n); ++i)
    if (ca[i] != cb[i]) return false;
  return true;
}
int main(void) {
  cin >> n;
  for (int i = int(0); i < int(n); ++i) cin >> a[i], axor ^= a[i];
  for (int i = int(0); i < int(n); ++i) cin >> b[i], bxor ^= b[i];
  a[n] = axor;
  b[n] = bxor;
  n++;
  if (check() == false) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = int(0); i < int(n - 1); ++i)
    if (a[i] != b[i]) ans++;
  if (ans != 0) ans++;
  if (axor != bxor) ans--;
  cout << ans << endl;
  return 0;
}
