#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  vector<long long> b(n);
  for (long long i = (0); i < (n); i++) cin >> b[i];
  long long x = 0;
  for (long long i = (0); i < (n); i++) x ^= a[i];
  long long cnt = 0;
  vector<long long> c, d;
  for (long long i = (0); i < (n); i++) {
    if (a[i] == b[i])
      cnt++;
    else {
      c.push_back(a[i]);
      d.push_back(b[i]);
    }
  }
  long long s = 1, t = 0;
  for (long long i = (0); i < (c.size()); i++) {
    if (x == c[i]) s++;
    if (x == d[i]) t++;
  }
  bool ff = s == t ? true : false;
  c.push_back(x);
  sort((c).begin(), (c).end());
  sort((d).begin(), (d).end());
  long long tmp = 0;
  bool f = true;
  for (long long i = (0); i < (d.size()); i++) {
    while (c[tmp] != d[i] && tmp < c.size()) tmp++;
    if (i + 1 < tmp) {
      f = false;
      break;
    }
    tmp++;
  }
  if (!f)
    cout << -1 << endl;
  else
    cout << (ff ? n - cnt : (n - cnt == 0 ? 0 : n - cnt + 1)) << endl;
  return 0;
}
