#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];
  int tmp = 0;
  for (int i = 0; i < N; i++) tmp ^= a[i];
  map<int, int> amp, bmp;
  for (int i : a) {
    amp[i] += 1;
  }
  amp[tmp] += 1;
  for (int i : b) {
    bmp[i] += 1;
  }
  for (pair<int, int> p : bmp) {
    if (amp[p.first] < p.second) {
      cout << -1 << endl;
      return 0;
    }
  }
  int count = 0;
  while (1) {
  loop:
    bool flag = false;
    for (int i = 0; i < N; i++) {
      if (a[i] != b[i] && b[i] == tmp) {
        swap(a[i], tmp);
        count += 1;
        flag = true;
      }
    }
    if (flag == false) {
      for (int i = 0; i < N; i++) {
        if (a[i] != b[i]) {
          swap(a[i], tmp);
          count += 1;
          goto loop;
        }
      }
      cout << count << endl;
      return 0;
    }
  }
}
