#include <bits/stdc++.h>
using namespace std;
int a[100100], b[100100];
int ta[100100], tb[100100];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  for (int i = 1; i <= n; ++i) {
    a[0] ^= a[i];
    b[0] ^= b[i];
    ta[i] = a[i];
    tb[i] = b[i];
    if (i == n) {
      ta[0] = a[0];
      tb[0] = b[0];
    }
  }
  sort(ta, ta + n + 1);
  sort(tb, tb + n + 1);
  for (int i = 0; i <= n; ++i)
    if (ta[i] != tb[i]) {
      puts("-1");
      exit(0);
    }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] != b[i]) ++ans;
  if (a[0] == b[0] && ans > 0) ++ans;
  printf("%d\n", ans);
  return 0;
}
