#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
template <typename T>
bool cmax(T &a, T b) {
  return (a < b) ? a = b, 1 : 0;
}
template <typename T>
bool cmin(T &a, T b) {
  return (a > b) ? a = b, 1 : 0;
}
template <typename T>
T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T>
void write(T x, char y) {
  if (x == 0) {
    putchar('0'), putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10) wr[++top] = x % 10 + '0';
  while (top) putchar(wr[top--]);
  putchar(y);
}
void file() {}
int n, a[N], b[N], c[N], d[N];
void input() {
  n = read<int>();
  for (register int i = (int)(1); i <= (int)(n); ++i) a[i] = c[i] = read<int>();
  for (register int i = (int)(1); i <= (int)(n); ++i) b[i] = d[i] = read<int>();
}
int ans = 0;
void work() {
  for (register int i = (int)(1); i <= (int)(n); ++i) c[n + 1] ^= c[i];
  for (register int i = (int)(1); i <= (int)(n); ++i) d[n + 1] ^= d[i];
  int C = c[n + 1], D = d[n + 1];
  sort(c + 1, c + n + 2);
  sort(d + 1, d + n + 2);
  for (register int i = (int)(1); i <= (int)(n + 1); ++i)
    if (c[i] ^ d[i]) {
      puts("-1");
      return;
    }
  int flag = (C == D);
  for (register int i = (int)(1); i <= (int)(n); ++i)
    if (a[i] ^ b[i]) {
      ans++;
      if (a[i] == D) flag = 0;
    }
  write(ans + flag, '\n');
}
int main() {
  input();
  work();
  return 0;
}
