#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int N;
  scanf("%d", &N);
  unsigned a[N], a_[N + 1], b[N], b_[N], x = 0;
  for (int i = 0; i < N; i++) {
    scanf("%u", a + i);
    a_[i] = a[i];
    x ^= a[i];
  }
  a_[N] = x;
  for (int i = 0; i < N; i++) {
    scanf("%u", a + i);
    b_[i] = b[i];
  }
  sort(a_, a_ + N + 1);
  sort(b_, b_ + N);
  bool has_replaced = false;
  for (int j = 0; j < N; ++j) {
    if (has_replaced && a_[j + 1] != b_[j]) {
      printf("-1\n");
      return 0;
    } else if (!has_replaced && a_[j] != b_[j]) {
      has_replaced = true;
    }
  }
  int answer = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i] != b[i]) answer++;
  }
  printf("%d\n", answer);
  return 0;
}
