#include <bits/stdc++.h>
using namespace std;
const int N = 1 * 100 * 1000 + 1;
int n, x, a[N], b[N], ans;
map<int, int> cnt;
bool chek;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    a[n] ^= a[i];
  }
  cnt[a[n]]++;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    b[n] ^= b[i];
    cnt[b[i]]--;
    if (cnt[b[i]] < 0) return cout << -1 << endl, 0;
  }
  for (int i = 1; i <= n; i++) ans += (a[i] != b[i]);
  cout << ans << endl;
}
