#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}
int n, a[1000005], b[1000005], c[1000005], d[1000005], cnt, num, nw, F, fl;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read(), num ^= a[i];
  for (int i = 1; i <= n; i++) b[i] = read();
  for (int i = 1; i <= n; i++)
    if (a[i] != b[i]) c[++cnt] = a[i], d[cnt] = b[i];
  a[++cnt] = num;
  sort(a + 1, a + cnt + 1);
  sort(b + 1, b + cnt);
  nw = 1;
  for (int i = 1; i <= (cnt - 1); i++) {
    if (a[nw] != b[i]) {
      if (!F) {
        F = 1;
        nw++;
        fl = i;
        if (a[nw] != b[i]) {
          F = 2;
          break;
        }
      } else {
        F = 2;
        break;
      }
    }
    nw++;
  }
  if (F == 2) return puts("-1"), 0;
  if (a[fl] == num)
    cout << cnt << endl;
  else
    cout << cnt - 1 << endl;
  return 0;
}
