#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
using vec = vector<long long>;
using mat = vector<vec>;
using Pii = pair<long long, long long>;
using PiP = pair<long long, Pii>;
using PPi = pair<Pii, long long>;
using bools = vector<bool>;
using pairs = vector<Pii>;
template <typename T>
void readv(vector<T> &a) {
  for (long long i = (0); i < (a.size()); i++) cin >> a[i];
}
void readv_m1(vector<long long> &a) {
  for (long long i = (0); i < (a.size()); i++) {
    cin >> a[i];
    a[i]--;
  }
}
long long mod = 1000000007;
signed main() {
  long long N;
  cin >> N;
  vec a(N), b(N);
  readv(a);
  readv(b);
  long long A = 0, B = 0;
  for (long long i = (0); i < (N); i++) A ^= a[i];
  for (long long i = (0); i < (N); i++) B ^= b[i];
  a.push_back(A);
  b.push_back(B);
  vec a2 = a, b2 = b;
  sort(a2.begin(), a2.end());
  sort(b2.begin(), b2.end());
  if (a2 != b2) {
    cout << -1 << endl;
    return 0;
  }
  long long ans = 0;
  for (long long i = (0); i < (N); i++)
    if (a[i] != b[i]) ans++;
  if (a[N] == b[N]) ans++;
  if (a == b) ans = 0;
  cout << ans << endl;
  return 0;
}
