#include <bits/stdc++.h>
using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr int INF = 1000000000;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int x = 0;
  for (int& v : a) {
    cin >> v;
    x ^= v;
  }
  int y = 0;
  for (int& v : b) {
    cin >> v;
    y ^= v;
  }
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  int diff = 0;
  for (int i = (0); i < (n); ++i)
    if (a[i] != b[i]) ++diff;
  sort(begin(a), end(a));
  sort(begin(b), end(b));
  if (a == b) ++diff;
  a.push_back(x);
  b.push_back(y);
  sort(begin(a), end(a));
  sort(begin(b), end(b));
  if (a == b) {
    cout << diff << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
