#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
int n, a[N], b[N], x = 0;
map<int, int> Ma, Mb;
int main() {
  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int mismatch = 0;
  cin >> n;
  for (long long int i = (1); i <= (n); i++) cin >> a[i], x ^= a[i], Ma[a[i]]++;
  for (long long int i = (1); i <= (n); i++) cin >> b[i], Mb[b[i]]++;
  for (long long int i = (1); i <= (n); i++) mismatch += (a[i] == b[i] ? 0 : 1);
  Ma[x]++;
  if (mismatch == 0) {
    cout << 0 << endl;
    return 0;
  }
  int diff = 0;
  for (auto p : Mb) {
    if (Ma[p.first] < p.second) {
      cout << -1 << endl;
      return 0;
    }
  }
  Ma[x]--;
  bool isPerm = true;
  for (auto p : Mb) {
    if (p.second != Ma[p.first]) {
      isPerm = false;
      break;
    }
  }
  if (isPerm) {
    cout << mismatch + 1 << endl;
    return 0;
  }
  cout << mismatch << endl;
  return 0;
}
