#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N;
  cin >> N;
  vector<unsigned long long> a(N);
  vector<unsigned long long> b(N);
  vector<unsigned long long> sa(N);
  vector<unsigned long long> sb(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }
  unsigned long long x = 0;
  for (int i = 0; i < N; i++) {
    x = x ^ a[i];
  }
  a.push_back(x);
  x = 0;
  for (int i = 0; i < N; i++) {
    x = x ^ b[i];
  }
  b.push_back(x);
  sa = a;
  sb = b;
  sort(sa.begin(), sa.end());
  sort(sb.begin(), sb.end());
  for (int i = 0; i <= N; i++) {
    if (sa[i] != sb[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] != b[i]) {
      res++;
    }
  }
  if (a[N] == b[N] && res > 0) {
    res++;
  }
  cout << res << endl;
  return 0;
}
