#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "sz = " << vc.size() << endl << "[";
  for (const T& v : vc) o << v << ",";
  o << "]";
  return o;
}
using ll = long long;
constexpr ll MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  ll init_x = 0;
  for (ll i = 0; i < (n); i++) {
    cin >> a[i];
    init_x ^= a[i];
  }
  for (ll i = 0; i < (n); i++) {
    cin >> b[i];
  }
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> distincta;
  vector<ll> distinctb;
  for (ll i = 0; i < (n); i++) {
    if (a[i] != b[i]) {
      distincta.push_back(a[i]);
      distinctb.push_back(b[i]);
    }
  }
  vector<ll> a_ = distincta;
  vector<ll> b_ = distinctb;
  sort(a_.begin(), a_.end());
  sort(b_.begin(), b_.end());
  ll mini = numeric_limits<int>::max() / 100;
  if (a_ == b_) {
    mini = a_.size() + 1;
    cout << a_.size() + 1 << endl;
    return 0;
  } else {
    const int anum = upper_bound(a_.begin(), a_.end(), init_x) -
                     lower_bound(a_.begin(), a_.end(), init_x);
    const int bnum = upper_bound(b_.begin(), b_.end(), init_x) -
                     lower_bound(b_.begin(), b_.end(), init_x);
    if (bnum - anum >= 0 and bnum - anum <= 1) {
      int diff_num = -1;
      int diff = 0;
      for (int i = 0; i < a_.size(); i++) {
        if (a_[i] != init_x) {
          const int anum = upper_bound(a_.begin(), a_.end(), a_[i]) -
                           lower_bound(a_.begin(), a_.end(), a_[i]);
          const int bnum = upper_bound(b_.begin(), b_.end(), a_[i]) -
                           lower_bound(b_.begin(), b_.end(), a_[i]);
          if (anum == bnum + 1) {
            diff++;
            diff_num = a_[i];
          } else if (anum != bnum) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
      if (diff != 1) {
        cout << -1 << endl;
        return 0;
      } else {
        for (int i = 0; i < distinctb.size(); i++) {
          if (distinctb[i] == init_x) {
            distinctb[i] = diff_num;
            break;
          }
        }
        ll sum = 0;
        for (int i = 0; i < distincta.size(); i++) {
          if (distincta[i] != distinctb[i]) {
            sum++;
          }
        }
        cout << sum << endl;
        return 0;
      }
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}
