#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int inf = 1e9;
const long double eps = 1e-8;
const int Q = 1e9 + 7;
int countInv = 0;
void mergeSort(vector<int> &a, long long l, long long r) {
  if (l == r) return;
  long long m = (l + r) / 2;
  mergeSort(a, l, m);
  mergeSort(a, m + 1, r);
  vector<int> b(m - l + 1);
  vector<int> c(r - m);
  for (int i = l; i <= m; i++) b[i - l] = a[i];
  for (int i = m + 1; i <= r; i++) c[i - m - 1] = a[i];
  long long bc = 0, cc = 0;
  for (int i = l; i <= r; i++) {
    if (bc + l == m + 1) {
      a[i] = c[cc];
      cc++;
    } else if (cc + m + 1 == r + 1) {
      a[i] = b[bc];
      bc++;
    } else {
      if (b[bc] < c[cc]) {
        a[i] = b[bc];
        bc++;
      } else {
        a[i] = c[cc];
        countInv += m - l - bc + 1;
        cc++;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  multiset<int> s;
  int x = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x = x ^ a[i];
    s.insert(a[i]);
  }
  s.insert(x);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    auto it = s.find(b[i]);
    if (it == s.end()) {
      cout << -1;
      return 0;
    }
    s.erase(it);
  }
  int count = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) count++;
  if (*s.begin() == x && count > 0) count++;
  cout << count;
  return 0;
}
