#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[100010], x, ans = 0;
map<int, int> ma, mb;
void init() {
  freopen("duliu.in", "r", stdin);
  freopen("duliu.out", "w", stdout);
}
int main() {
  init();
  int flag = 0;
  scanf("%d", &n);
  x = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), x ^= a[i], ma[a[i]]++;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]), mb[b[i]]++;
    if (mb[b[i]] > ma[b[i]]) {
      if (b[i] != x)
        flag = 2;
      else
        flag++;
    }
  }
  if (flag >= 2) return puts("-1"), 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) {
      ans++;
    }
  }
  if (ans == n && flag) flag--;
  printf("%d\n", ans + 1 - flag);
}
