#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], m, b[N], k, ans = 1;
map<int, int> D;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), m ^= a[i], D[a[i]]++;
  if (D[m]++ > 1) m = -1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]), D[b[i]]--, ans += a[i] != b[i];
  for (auto& i : D) {
    if (i.second < 0) puts("-1"), exit(0);
    if (i.second > 0) ans -= i.first != m;
  }
  printf("%d\n", ans);
  return 0;
}
