#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int N;
long long int A[MAX_N], B[MAX_N];
map<long long int, int> MPA, MPB;
int calc() {
  long long int x = 0, y = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    x ^= A[i];
    y ^= B[i];
    if (A[i] != B[i]) cnt++;
  }
  if (cnt == 0) return 0;
  map<long long int, int> mpa, mpb;
  mpa[x] = mpb[y] = 1;
  for (int i = 0; i < N; i++) {
    mpa[A[i]]++;
    mpb[B[i]]++;
  }
  for (auto p : mpa)
    if (p.second != mpb[p.first]) return -1;
  if (x == y) cnt++;
  return cnt;
}
void solve() { cout << calc() << endl; }
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  solve();
  return 0;
}
