#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000001;
const long long LINF = 1000000000000000001LL;
struct FAU {
  vector<int> p, r;
  FAU(int n) : p(n, -1), r(n, 0) {}
  int find(int x) {
    if (p[x] == -1) return x;
    return p[x] = find(p[x]);
  }
  void join(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] > r[y])
      p[y] = x;
    else
      p[x] = y;
    if (r[x] == r[y]) ++r[y];
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = (0); i <= (n - 1); ++i) cin >> a[i];
  for (int i = (0); i <= (n - 1); ++i) cin >> b[i];
  int xr = 0;
  for (int x : a) xr ^= x;
  multiset<int> s = {xr};
  for (int x : a) s.insert(x);
  for (int x : b) {
    if (!s.count(x)) {
      cout << -1;
      return 0;
    }
    s.erase(s.find(x));
  }
  int ans = 0;
  for (int i = (0); i <= (n - 1); ++i) ans += (a[i] != b[i]);
  int c = 0;
  for (int x : a)
    if (x == xr) c++;
  for (int x : b)
    if (x == xr) c--;
  if (c == 0) ans++;
  cout << ans;
  return 0;
}
