#include <bits/stdc++.h>
using namespace std;
int solve(int n, vector<int> const& a, vector<int> const& b) {
  if (a == b) {
    return 0;
  }
  int sum_a = accumulate(begin(a), end(a), 0, bit_xor<int>());
  map<int, int> cnt;
  for (int a_i : a) {
    cnt[a_i] += 1;
  }
  cnt[sum_a] += 1;
  for (int b_i : b) {
    if (cnt.count(b_i)) {
      cnt[b_i] -= 1;
      if (cnt[b_i] == 0) {
        cnt.erase(b_i);
      }
    }
  }
  assert(not cnt.empty());
  if (cnt.size() >= 2 or cnt.begin()->second >= 2) {
    return -1;
  }
  int removed = cnt.begin()->first;
  int result = 0;
  for (int i = 0; (i) < int(n); ++(i)) {
    result += (a[i] != b[i]);
  }
  result += (sum_a == removed);
  return result;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; (i) < int(n); ++(i)) scanf("%d", &a[i]);
  vector<int> b(n);
  for (int i = 0; (i) < int(n); ++(i)) scanf("%d", &b[i]);
  int result = solve(n, a, b);
  printf("%d\n", result);
  return 0;
}
