#include <bits/stdc++.h>
using namespace std;
long long a[114514];
long long b[114514];
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < (n); i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < (n); i++) {
    cin >> b[i];
  }
  long long all = 0;
  for (long long i = 0; i < (n); i++) {
    all = all ^ a[i];
  }
  long long ans = 0;
  map<long long, long long> mp;
  mp[all]++;
  for (long long i = 0; i < (n); i++) {
    if (a[i] != b[i]) {
      ans++;
      mp[a[i]]++;
    }
  }
  for (long long i = 0; i < (n); i++) {
    if (a[i] != b[i]) {
      if (mp[b[i]] == 0) {
        cout << -1 << endl;
        return 0;
      }
      mp[b[i]]--;
    }
  }
  if (ans == 0) {
    cout << 0 << endl;
  } else if (mp[all] > 0) {
    cout << ans + 1 << endl;
  } else {
    cout << ans << endl;
  }
}
