#include <bits/stdc++.h>
using namespace std;
int n, a[100005], b[100005], x;
map<int, int> mp;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    x ^= a[i];
    mp[a[i]]++;
  }
  mp[x]++;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    if (!mp[b[i]]) {
      printf("-1\n");
      return 0;
    }
    mp[b[i]]--;
  }
}
