#include <bits/stdc++.h>
using namespace std;
int N, a[100100], b[100100];
map<int, int> m;
void d(int z) {
  int x = 0;
  for (int i = (0); i < (N); i++) x ^= a[i];
  a[z] = x;
}
void print() {
  for (int i = (0); i < (N); i++) printf("%d%c", b[i], " \n"[i == N - 1]);
}
int main() {
  scanf("%d", &N);
  int xr = 0, num = 0;
  for (int i = (0); i < (N); i++) scanf("%d", &a[i]), m[a[i]]++, xr ^= a[i];
  for (int i = (0); i < (N); i++) scanf("%d", &b[i]), m[b[i]]--;
  m[xr]++;
  for (int i = (0); i < (N); i++)
    if (a[i] != b[i]) num++;
  if (num == 0) {
    puts("0");
    return 0;
  }
  int numover = 0, disc = -1;
  for (auto i : m) {
    if (i.second < 0) {
      puts("-1");
      return 0;
    }
    if (i.second > 0) {
      numover++;
      disc = i.first;
    }
  }
  if (numover > 1) {
    puts("-1");
    return 0;
  }
  printf("%d\n", num + (disc == xr));
  return 0;
}
