#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long a[N], b[N];
int main() {
  int n;
  scanf("%d", &n);
  long long x = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%i64d", &a[i]);
    x = x ^ a[i];
  }
  a[n + 1] = x;
  int ans = 0;
  for (int i = 1; i <= n; i++) scanf("%i64d", &b[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) ans++;
  long long num = -1;
  sort(a + 1, a + n + 2);
  sort(b + 1, b + n + 1);
  int i = 1, j = 1;
  while (i != n + 2 && j != n + 1) {
    if (a[i] == b[j]) {
      a[i] = -1;
      b[j] = -1;
      i++;
      j++;
    }
    if (a[i] < b[j]) i++;
    if (a[i] > b[j]) j++;
  }
  j = 0;
  for (int i = 1; i <= n + 1; i++)
    if (a[i] != -1) j++;
  if (j != 1) {
    puts("-1");
    return 0;
  }
  if (ans == 0) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n + 1; i++)
    if (a[i] == x) ans++;
  printf("%d\n", ans);
}
