#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int N, A, a[maxn], b[maxn];
bool check() {
  static multiset<int> st;
  st.clear();
  st.insert(A);
  for (int i = 1; i <= N; ++i) st.insert(a[i]);
  for (int i = 1; i <= N; ++i) {
    if (!st.count(b[i])) return false;
    st.erase(st.find(b[i]));
  }
  ++N;
  a[N] = A;
  b[N] = *st.begin();
  return true;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", a + i), A ^= a[i];
  for (int i = 1; i <= N; ++i) scanf("%d", b + i);
  if (!check()) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  for (int i = 1; i < N; ++i) ans += a[i] != b[i];
  if (ans) ans += a[N] == b[N];
  printf("%d\n", ans);
  return 0;
}
