#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  vector<int> a, b;
  int n, s = 0;
  cin >> n;
  a.reserve(n);
  b.reserve(n);
  for (int t, i = 0; i < n; ++i) {
    cin >> t;
    a.push_back(t);
    s ^= t;
  }
  a.push_back(s);
  s = 0;
  for (int t, i = 0; i < n; ++i) {
    cin >> t;
    b.push_back(t);
    s ^= t;
  }
  b.push_back(s);
  sort(begin(a), end(a));
  sort(begin(b), end(b));
  if (a != b) {
    cout << "-1\n";
    return 0;
  }
  assert(0);
  return 0;
}
