#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  int x = 0;
  for (int i = (int)(0); i < (int)(N); i++) {
    cin >> a[i];
    x ^= a[i];
  }
  int d = 0;
  for (int i = (int)(0); i < (int)(N); i++) {
    cin >> b[i];
    if (a[i] != b[i]) d++;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  bool same = true;
  set<int> dif;
  for (int i = (int)(0); i < (int)(N); i++) {
    if (a[i] != b[i]) {
      same = false;
      dif.insert(b[i]);
      break;
    }
  }
  if (same) {
    for (int i = (int)(0); i < (int)(N); i++) {
      if (b[i] == d && dif.find(d) != dif.end()) {
        cout << d << endl;
        return 0;
      }
    }
    cout << d + 1 << endl;
    return 0;
  }
  a.push_back(d);
  sort(a.begin(), a.end());
  same = true;
  int off = 0;
  for (int i = (int)(0); i < (int)(N); i++) {
    if (a[i + off] != b[i]) {
      if (off == 0) {
        off = 1;
      } else {
        same = false;
      }
    }
  }
  if (same) {
    cout << d << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
