#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char ch = getchar();
  bool f = 0;
  for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
  for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
  x = f ? -x : x;
}
const int N = 100010;
map<int, int> m;
int n, a[N], b[N], ans, tmp;
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) read(a[i]), ++m[a[i]], tmp ^= a[i];
  ++m[tmp];
  for (register int i = 1; i <= n; ++i) {
    read(b[i]);
    if (b[i] ^ a[i])
      if (!m[b[i]]) {
        puts("-1");
        return 0;
      } else
        ++ans;
    --m[b[i]];
  }
  if (m[tmp]) ++ans;
  return printf("%d", ans) & 0;
}
