#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
int n;
int ar[100005], br[100005];
void ng() {
  puts("-1");
  exit(0);
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) scanf("%d", &ar[i]);
  for (int i = 0; i < (n); ++i) scanf("%d", &br[i]);
  {
    bool suc = true;
    for (int i = 0; i < (n); ++i)
      if (ar[i] != br[i]) suc = false;
    if (suc) {
      puts("0");
      return 0;
    }
  }
  int all = 0;
  for (int i = 0; i < (n); ++i) all ^= ar[i];
  map<int, int> X, Y;
  for (int i = 0; i < (n); ++i) X[ar[i]]++;
  for (int i = 0; i < (n); ++i) X[br[i]]--;
  bool allzero = true;
  for (auto e : X)
    if (e.second != 0) allzero = false;
  if (allzero) {
    int res = 0;
    for (int i = 0; i < (n); ++i)
      if (ar[i] != br[i]) ++res;
    ++res;
    cout << res << endl;
  } else {
    int p = -1, q = -1;
    for (auto e : X) {
      if (e.second != 0) {
        Y[e.first] += e.second;
        if (abs(e.second) != 1) ng();
        if (e.second > 0)
          p = e.first;
        else
          q = e.first;
      }
    }
    if (Y.size() != 2) ng();
    if (q != all) ng();
    int res = 0;
    for (int i = 0; i < (n); ++i) {
      if (ar[i] != br[i]) ++res;
    }
    cout << res << endl;
  }
  return 0;
}
