#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
unordered_map<int, int> T;
int a[N], b[N], n, ret;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]), a[n] ^= a[i];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]), b[n] ^= b[i];
    if (a[i] != b[i]) ++ret;
  }
  for (int i = 0; i <= n; ++i) ++T[a[i]], --T[b[i]];
  for (auto u : T)
    if (u.second) return puts("-1"), 0;
  if (ret && a[n] == b[n]) ++ret;
  printf("%d\n", ret);
  return 0;
}
