#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, int> Map;
map<int, vector<int> > pos;
int n, m, x, y, A[N], B[N], C[N];
map<int, int> fa;
int getf(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getf(fa[x]);
}
int main() {
  scanf("%d", &n);
  int cur = 0;
  for (int i = 1; i <= n; ++i) scanf("%d", &A[i]), ++Map[A[i]], cur ^= A[i];
  A[n + 1] = cur;
  int now = 0;
  ++Map[cur];
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &B[i]);
    now ^= B[i];
    --Map[B[i]];
    if (Map[B[i]] < 0) {
      exit(0 * puts("-1"));
    }
  }
  exit(0 * puts("-1"));
  B[++n] = now;
  for (int i = 1; i <= n; ++i)
    if (A[i] != B[i]) {
      fa[A[i]] = A[i];
      fa[B[i]] = B[i];
    }
  int tot = 0;
  for (int i = 1; i < n; ++i) tot += (A[i] != B[i]);
  if (!tot) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (A[i] != B[i] || i == n - 1) {
      fa[getf(A[i])] = getf(B[i]);
    }
  }
  for (map<int, int>::iterator jxc = fa.begin(); jxc != fa.end(); ++jxc) {
    if (fa[(jxc->first)] == (jxc->first)) ++tot;
  }
  --tot;
  cout << tot << endl;
}
