#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int n;
int a[MAX_N];
int b[MAX_N];
int main() {
  cin >> n;
  int x = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    x ^= a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  int d = 0;
  for (int i = 0; i < n; ++i) {
    d += (a[i] == b[i] ? 0 : 1);
  }
  if (d == 0) {
    cout << 0 << endl;
    return 0;
  }
  map<int, int> ma, mb;
  for (int i = 0; i < n; i++) {
    ma[a[i]]++;
    mb[b[i]]++;
  }
  if (mb[x] - ma[x] > 1) {
    cout << -1 << endl;
    return 0;
  }
  bool b = false;
  for (auto p : ma) {
    if (p.first == x || p.second == mb[p.first]) continue;
    if (p.second - mb[p.first] == 1 && !b) {
      b = true;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (b && mb[x] - ma[x] == 1) {
    cout << d << endl;
  } else if (b) {
    cout << -1 << endl;
  } else {
    cout << d + 1 << endl;
  }
  return 0;
}
