#include <bits/stdc++.h>
using namespace std;
const long double M_PI = 3.14159265358979323846265;
const long long INFL = 1LL << 60;
void pres(long double A, long long x = 10) {
  cout << fixed << setprecision(x) << A << endl;
}
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N), B(N);
  long long Axor = 0;
  for (long long i = 0; i < (N); i++) {
    cin >> A[i];
    Axor ^= A[i];
  }
  for (long long i = 0; i < (N); i++) cin >> B[i];
  bool same = 1;
  for (long long i = 0; i < (N); i++) {
    if (A[i] != B[i]) same = 0;
  }
  if (same) {
    cout << 0 << endl;
    return 0;
  }
  map<long long, long long> b;
  for (long long i = 0; i < (N); i++) {
    b[B[i]]++;
  }
  for (long long i = 0; i < (N); i++) {
    b[A[i]]--;
  }
  b[Axor]--;
  for (long long i = 0; i < (N); i++) {
    if (b[B[i]] >= 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long ans = 0;
  if (b[Axor] == -1) {
    ans++;
  }
  for (long long i = 0; i < (N); i++) {
    if (A[i] != B[i]) ans++;
  }
  cout << ans << endl;
}
