#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x = 0;
  vi a, b;
  map<int, int> cnt;
  cin >> n;
  a.resize(n);
  for (auto &i : a) cin >> i, cnt[i]++, x ^= i;
  cnt[x]++;
  b.resize(n);
  for (auto &i : b) cin >> i, cnt[i]--;
  if (a == b) return cout << 0, 0;
  for (auto i : cnt)
    if (i.second < 0) return cout << -1, 0;
  int ans = 0;
  for (int i = 0; i < n; i++) ans += a[i] != b[i];
  if (cnt[x]) ans++;
  cout << ans;
}
