#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      d++;
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int x = 0;
  for (int i = 0; i < n; i++) {
    x ^= a[i];
  }
  bool e = true;
  bool y = false;
  bool z = false;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (b[i] == x) {
        y = true;
        b.erase(b.begin() + i);
        break;
      } else {
        z = true;
        a.erase(a.begin() + i);
        break;
      }
    }
  }
  for (int i = 0; i < min(a.size(), b.size()); i++) {
    if (a[i] != b[i]) {
      if (b[i] != x && z) {
        cout << -1 << '\n';
        return 0;
      }
      if (y) {
        z = true;
        a.erase(a.begin() + i);
        break;
      }
    }
  }
  if ((int)a.size() < (int)b.size()) {
    b.pop_back();
    y = true;
  } else if ((int)a.size() > (int)b.size()) {
    a.pop_back();
    z = true;
  }
  assert(y == z);
  assert((int)a.size() == (int)b.size());
  for (int i = 0; i < min(a.size(), b.size()); i++) {
    if (a[i] != b[i]) {
      e = false;
      break;
    }
  }
  if (!e) {
    cout << -1 << '\n';
  } else {
    if (y) {
      cout << d << '\n';
    } else {
      cout << (d == 0 ? 0 : d + 1) << '\n';
    }
  }
  return 0;
}
