#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
int a[N], b[N];
void imp() {
  puts("-1");
  exit(0);
}
int main() {
  scanf("%d", &n);
  int xsm = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    xsm ^= a[i];
  }
  multiset<int> tr;
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    tr.insert(b[i]);
  }
  for (int i = 0; i < n; i++) {
    if (tr.find(a[i]) != tr.end()) {
      tr.erase(tr.find(a[i]));
    }
  }
  if (tr.size() > 1) imp();
  if (tr.size() == 1 && *tr.begin() != xsm) imp();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (a[i] != b[i]);
  }
  if (ans) ans += (tr.size() == 0);
  printf("%d\n", ans);
  return 0;
}
