#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100010;
int n, A[Maxn], B[Maxn], Start, N;
bool Same;
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) Start ^= A[i];
  for (int i = 1; i <= n; ++i)
    if (A[i] != B[i]) {
      ++N;
      A[N] = A[i];
      B[N] = B[i];
    }
  if (N == 0) {
    printf("0\n");
    return 0;
  }
  sort(A + 1, A + N + 1);
  sort(B + 1, B + N + 1);
  Same = true;
  for (int i = 1; i <= N; ++i)
    if (A[i] != B[i]) {
      Same = false;
      break;
    }
  if (Same) {
    printf("%d\n", N + 1);
    return 0;
  }
  for (int i = 1; i <= N; ++i)
    if (A[i] != B[i]) {
      A[i] = Start;
      break;
    }
  sort(A + 1, A + N + 1);
  sort(B + 1, B + N + 1);
  for (int i = 1; i <= N; ++i)
    if (A[i] != B[i]) {
      printf("-1\n");
      return 0;
    }
  printf("%d\n", N);
  return 0;
}
