#include <bits/stdc++.h>
using namespace std;
int a[1000100], b[1000100];
multiset<int> mp;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp.insert(a[i]);
    a[n + 1] ^= a[i];
  }
  mp.insert(a[n + 1]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (mp.find(b[i]) == mp.end()) {
      cout << -1 << endl;
      return 0;
    }
    mp.erase(mp.find(b[i]));
  }
  b[n + 1] = *mp.begin();
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) ans++;
  if (ans == 0) cout << ans << endl;
  if (a[n + 1] == b[n + 1]) ans++;
  cout << ans << endl;
}
