#include <bits/stdc++.h>
using namespace std;
int t1[1100000], t2[1100000];
int main() {
  long long n;
  cin >> n;
  map<long long, long long> mp1;
  vector<long long> v1, v2;
  int x, xorin = 0;
  int diff = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    t1[x]++;
    xorin ^= x;
    v1.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (v1[i] != x) diff++;
    t2[x]++;
    t1[x]--;
    v2.push_back(x);
  }
  int a = -9, b = -9, no = 0;
  for (int i = 0; i < 1100000; i++) {
    if (t1[i] == 1)
      a = i;
    else if (t1[i] == -1)
      b = i;
    else if (t1[i] == 1)
      a = i;
    else if (t1[i] != 0)
      no = 1;
  }
  if (no || (b != xorin && b != -9)) {
    cout << -1 << endl;
  } else {
    if (xorin != b && b != -9) {
      diff++;
    } else if (a == -9 && b == -9 && diff)
      diff++;
    cout << diff;
  }
  return 0;
}
