#include <bits/stdc++.h>
const long long N = 3e3 + 10;
const long long mod = 1e8 + 7;
using namespace std;
template <typename tp>
inline void read(tp &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
long long n, at, ans, flag;
long long xx[100010];
long long to[100010];
map<long long, long long> Map;
signed main() {
  read(n);
  for (long long i = 1; i <= n; i++) read(xx[i]), at ^= xx[i], Map[xx[i]]++;
  Map[at]++;
  for (long long i = 1; i <= n; i++) read(to[i]);
  for (long long i = 1; i <= n; i++) {
    if (Map[to[i]] == 0)
      return 0 * puts("-1");
    else
      Map[to[i]]--;
  }
  for (long long i = 1; i <= n; i++)
    if (to[i] == at) flag++;
  for (long long i = 1; i <= n; i++)
    if (to[i] != xx[i]) ans++;
  if (!flag) ans++;
  printf("%lld\n", ans);
  return 0;
}
