#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  bool CAN = true;
  long long N, t = 0, ans = 0;
  cin >> N;
  long long A[N], B[N];
  map<long long, long long> AA, BB;
  for (int i = (0); i < (N); ++i) {
    cin >> A[i];
    AA[A[i]]++;
    t ^= A[i];
  }
  AA[t]++;
  for (int i = (0); i < (N); ++i) {
    cin >> B[i];
    BB[B[i]]++;
  }
  for (int i = (0); i < (N); ++i) {
    if (AA[B[i]] < BB[B[i]]) CAN = false;
  }
  if (CAN) {
    long long P = 0;
    for (int i = (0); i < (N); ++i) {
      if (A[i] != B[i]) P++;
    }
    if (P == 0)
      ans = 0;
    else if (AA[t] == BB[t])
      ans = P;
    else
      ans = P + 1;
  } else
    ans = -1;
  cout << ans << '\n';
  return 0;
}
