#include <bits/stdc++.h>
using namespace std;
const int MC = 100010;
int N;
int a[MC], c[MC];
int b[MC], d[MC];
bool w[MC];
int main() {
  scanf("%d", &N);
  int x = 0;
  for (int i = (int)(0); i < (int)(N); ++i) {
    scanf("%d", a + i);
    c[i] = a[i];
    x ^= a[i];
  }
  for (int i = (int)(0); i < (int)(N); ++i) {
    scanf("%d", b + i);
    d[i] = b[i];
  }
  sort(c, c + N);
  sort(d, d + N);
  c[N] = -1;
  int z = 0;
  int r = 0;
  for (int i = (int)(0); i < (int)(N); ++i) {
    if (c[i + z - r] == d[i]) continue;
    if (r == 0 && x == d[i]) {
      r = 1;
      continue;
    }
    ++z;
    --i;
    if (r + z > 1) {
      printf("-1\n");
      return 0;
    }
  }
  int p = 0;
  for (int i = (int)(0); i < (int)(N); ++i) {
    w[i] = a[i] == b[i];
    if (w[i]) ++p;
  }
  printf("%d\n", N - p + (r == 1 || p == N ? 0 : 1));
  return 0;
}
