#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long mod = 1e9 + 7;
int n, s[N], t[N], ans;
int s2[N], t2[N];
map<int, int> cnt1, cnt2, ok;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) cin >> t[i];
  for (int i = 1; i <= n; i++) s[n + 1] ^= s[i];
  for (int i = 1; i <= n + 1; i++) cnt1[s[i]]++;
  for (int i = 1; i <= n; i++) cnt2[t[i]]++;
  for (int i = 1; i <= n; i++)
    if (cnt2[t[i]] > cnt1[t[i]]) {
      cout << -1;
      return 0;
    }
  for (int i = 1; i <= n; i++) {
    if (s[i] != t[i])
      ans++;
    else
      ok[s[i]]++;
  }
  if (ok[s[n + 1]] == cnt1[s[n + 1]]) ans++;
  cout << ans;
  return 0;
}
