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