#include <bits/stdc++.h>
using namespace std;
int DuLiu[100005], Pos[100005], n, sum, ans;
int temp, top, S, T;
bool vis[100005];
struct jd {
  int v;
  int id, to;
} A[100005], B[100005];
int gg() {
  printf("-1");
  return 0;
}
bool cmp1(jd a, jd b) {
  if (a.v == b.v) return a.id > b.id;
  return a.v < b.v;
}
bool cmp2(jd a, jd b) { return a.id < b.id; }
void ck() {
  int i = S;
  while (i != 0) {
    vis[i] = 1;
    i = A[i].to;
  }
  for (int i = 1; i <= top; i++) {
    if (!vis[i]) {
      ans++;
      int j = i;
      while (!vis[j]) {
        vis[j] = 1;
        j = A[j].to;
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &DuLiu[i]), sum ^= DuLiu[i];
  for (int i = 1; i <= n; i++) scanf("%d", &Pos[i]);
  for (int i = 1; i <= n; i++)
    if (DuLiu[i] != Pos[i]) {
      ans++;
      ++top;
      A[top].v = DuLiu[i];
      B[top].v = Pos[i];
      A[top].id = B[top].id = top;
    }
  if (ans == 0) return printf("0"), 0;
  A[top + 1].v = sum;
  A[top + 1].id = top + 1;
  sort(A + 1, A + 2 + top, cmp1);
  sort(B + 1, B + 1 + top, cmp1);
  int i = 1, j = 1;
  while (j <= top && i <= top + 1) {
    if (B[j].v == sum) S = B[j].id;
    if (A[i].v != B[j].v) {
      T = A[i].id;
      temp++, i++;
    } else
      A[i].to = B[j].id, i++, j++;
  }
  if (temp > 1) return gg();
}
