#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T next_num() {
  T i = 0;
  char c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  bool flag = c == '-';
  flag ? c = getchar() : 0;
  while (i = i * 10 - '0' + c, isdigit(c = getchar()))
    ;
  return flag ? -i : i;
}
template <class T1, class T2>
inline void apmax(T1 &a, const T2 &b) {
  if (a < b) a = b;
}
template <class T1, class T2>
inline void apmin(T1 &a, const T2 &b) {
  if (b < a) a = b;
}
const int N = 100010;
int a[N], b[N], lsta[N], lstb[N];
inline int Main() {
  int n = (next_num<int>()), xora = 0, xorb = 0;
  map<int, queue<int> > m;
  for (int i = 1; i <= n; i++) {
    xora ^= a[i] = lsta[i] = (next_num<int>());
  }
  for (int i = 1; i <= n; i++) {
    xorb ^= b[i] = lstb[i] = (next_num<int>());
    if (a[i] != b[i]) {
      m[b[i]].push(a[i]);
    }
  }
  lsta[n + 1] = xora;
  sort(lsta + 1, lsta + n + 2);
  sort(lstb + 1, lstb + n + 1);
  for (int i = 1, j = 1; i <= n; i++, j++) {
    for (; j <= n + 1 && lsta[j] != lstb[i]; j++)
      ;
    if (j > n + 1) return -1;
  }
  int ans = 0;
  for (int i = xora; !m.empty(); ans++) {
    map<int, queue<int> >::iterator it = m.find(i);
    if (it == m.end()) {
      ans++;
      it = m.begin();
      it->second.push(i);
      i = it->second.front();
      it->second.pop();
      it = m.find(i);
    }
    assert(it != m.end());
    i = it->second.front();
    it->second.pop();
    if (it->second.empty()) {
      m.erase(it);
    }
  }
  return ans;
}
int main() {
  printf("%d\n", Main());
  return 0;
}
