#include <bits/stdc++.h>
using namespace std;
int n, x, a[100010], c[100010], b[100010], d[100010];
int ans;
int w;
inline int read() {
  char ch;
  bool f = false;
  int res = 0;
  while (((ch = getchar()) < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-')
    f = true;
  else
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) + ch - '0';
  return f ? ~res + 1 : res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    x = x ^ a[i];
    c[i] = a[i];
  }
  a[n + 1] = x;
  sort(a + 1, a + 2 + n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    d[i] = b[i];
  }
  sort(b + 1, b + 1 + n);
  w = 1;
  for (int i = 1; i <= n; i++) {
    if (b[i] != a[w] && b[i] != a[w + 1]) {
      printf("-1\n");
      return 0;
    }
    if (b[i] == a[w])
      w++;
    else if (b[i] != a[w]) {
      w += 2;
      if (w > n + 1 && i != n) {
        printf("-1\n");
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (d[i] != c[i]) ans++;
  bool TRE = true;
  for (int i = 1; i <= n; i++)
    if (d[i] == x) {
      TRE = false;
      break;
    }
  if (TRE == true && ans != 0) ans++;
  printf("%d\n", ans);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
