#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 12;
int n, a[maxn], b[maxn];
int val;
multiset<int> st;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    st.insert(a[i]);
    val = (val ^ a[i]);
  }
  st.insert(val);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (st.find(b[i]) == st.end()) return cout << -1, 0;
    st.erase(st.find(b[i]));
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) ans++;
  }
  if (ans && *st.begin() == val) ans++;
  cout << ans;
  return 0;
}
