#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
int n, ans, x = 0, opt = 0, t, a[maxn], b[maxn], c[maxn], d[maxn], flag = 1;
int main() {
  scanf("%d", &n);
  ans = n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    c[i] = a[i];
    x = x ^ a[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    d[i] = b[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) flag = 0;
  }
  if (flag) {
    printf("0\n");
    return 0;
  }
  sort(c + 1, c + n + 1);
  sort(d + 1, d + n + 1);
  c[n + 1] = -1;
  d[n + 1] = -1;
  flag = 2;
  for (int i = 1, j = 1; i <= n || j <= n; i++, j++) {
    if (c[i] != d[j]) {
      if (i == j) {
        if (flag == 2) {
          flag = 0;
          t = c[i];
          j--;
          continue;
        } else {
          printf("-1\n");
          flag = 3;
        }
      }
      if (i != j) {
        if (d[j] == x) {
          flag = 1;
          i--;
        } else {
          printf("-1\n");
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      ans--;
    }
  }
  if (flag == 2) {
    for (int i = 1; i <= n; i++) {
      if (b[i] == x) {
        opt = 1;
      }
    }
    printf("%d\n", ans - opt + 1);
  }
  if (flag == 1) {
    printf("%d\n", ans);
  }
  return 0;
}
