#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
namespace pb_ds {
namespace io {
const int MaxBuff = 1 << 15;
const int Output = 1 << 23;
char B[MaxBuff], *S = B, *T = B;
char Out[Output], *iter = Out;
inline void flush() {
  fwrite(Out, 1, iter - Out, stdout);
  iter = Out;
}
}  // namespace io
template <class Type>
inline Type Read() {
  using namespace io;
  register char ch;
  register Type ans = 0;
  register bool neg = 0;
  while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T)
                   ? 0
                   : *S++),
         (ch < '0' || ch > '9') && ch != '-')
    ;
  ch == '-' ? neg = 1 : ans = ch - '0';
  while (ch = ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T)
                   ? 0
                   : *S++),
         '0' <= ch && ch <= '9')
    ans = ans * 10 + ch - '0';
  return neg ? -ans : ans;
}
template <class Type>
inline void Print(register Type x, register char ch = '\n') {
  using namespace io;
  if (!x)
    *iter++ = '0';
  else {
    if (x < 0) *iter++ = '-', x = -x;
    static int s[100];
    register int t = 0;
    while (x) s[++t] = x % 10, x /= 10;
    while (t) *iter++ = '0' + s[t--];
  }
  *iter++ = ch;
}
}  // namespace pb_ds
using namespace pb_ds;
int n, a[N], b[N], ans, sta, k = -1;
map<int, int> cnt;
int main() {
  n = Read<int>();
  for (int i = 1; i <= n; ++i) a[i] = Read<int>(), ++cnt[a[i]], sta ^= a[i];
  ++cnt[sta];
  for (int i = 1; i <= n; ++i) b[i] = Read<int>(), --cnt[b[i]];
  for (int i = 1; i <= n; ++i) {
    ans += (a[i] != b[i]);
    if (cnt[b[i]] < 0) {
      printf("-1\n");
      return 0;
    }
  }
  if (!ans) {
    printf("0\n");
    return 0;
  }
  ++ans;
  for (int i = 1; i <= n; ++i)
    if (b[i] == sta && b[i] != a[i]) {
      --ans;
      break;
    }
  printf("%d\n", ans);
  return 0;
}
