#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 99;
int n, x, ans, a[N], b[N];
map<int, int> t;
int main() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &a[i]);
    ;
    a[0] ^= a[i];
    t[a[i]]++;
  }
  t[a[0]]++;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &b[i]);
    ;
    b[0] ^= b[i];
  }
  for (int i = 0; i < n + 1; i++) {
    t[b[i]]--;
    if (t[b[i]] < 0) return cout << -1, 0;
    ans += (a[i] != b[i]);
  }
  if (a[0] != b[0]) return cout << ans - 1, 0;
  cout << ans;
}
