#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 7;
int n;
int sum;
int m, ans;
int a[sz], b[sz];
int c[sz];
int head[sz], nxt[sz];
int cnt[sz], t[sz];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), c[i] = a[i], sum ^= a[i];
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]), c[n + i] = b[i];
  c[2 * n + 1] = sum;
  sort(c + 1, c + 2 * n + 2);
  m = unique(c + 1, c + 2 * n + 2) - c;
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(c + 1, c + m + 1, a[i]) - c;
    t[a[i]]++;
  }
  sum = lower_bound(c + 1, c + m + 1, sum) - c;
  t[sum]++;
  for (int i = 1; i <= n; i++) {
    b[i] = lower_bound(c + 1, c + m + 1, b[i]) - c;
    cnt[b[i]]++;
    nxt[i] = head[b[i]];
    head[b[i]] = i;
  }
  bool flag = 0;
  for (int i = 1; i <= m; i++)
    if (cnt[i] > t[i]) flag = 1;
  if (flag) return printf("-1\n"), 0;
}
