#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const MAXN = 110000;
int N;
int a[MAXN];
int b[MAXN];
map<int, vector<int>> posB;
bool was[MAXN];
bool dfs(int v) {
  was[v] = true;
  if (!posB.count(a[v])) return false;
  for (int u : posB[a[v]])
    if (!was[u] && !dfs(u)) return false;
  return true;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cin >> N;
  for (int i = 0; i < (N); ++i) cin >> a[i];
  for (int i = 0; i < (N); ++i) cin >> b[i];
  for (int i = 0; i < (N); ++i) a[N] ^= a[i];
  for (int i = 0; i < (N); ++i) b[N] ^= b[i];
  int res = 0;
  for (int i = 0; i < (N + 1); ++i)
    if (a[i] != b[i]) {
      res++;
      posB[b[i]].push_back(i);
    }
  if (a[N] != b[N]) res--;
  int cc = 0;
  for (int i = 0; i < (N + 1); ++i)
    if (a[i] != b[i] && !was[i]) {
      cc++;
      if (!dfs(i)) {
        cout << "-1\n";
        return 0;
      }
    }
  if (cc > 0) res += cc - 1;
  cout << res << "\n";
}
