#include <bits/stdc++.h>
using namespace std;
map<int, int> acnt;
const int MAXN = 100010;
int a[MAXN], b[MAXN];
map<int, vector<int> > idx;
int start = 0;
int main() {
  int axor = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    axor ^= a[i];
    acnt[a[i]]++;
  }
  acnt[axor]++;
  bool hasxor = false;
  bool cant = false;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == axor) hasxor = true;
    if (acnt[b[i]] == 0)
      cant = true;
    else
      acnt[b[i]]--;
  }
  if (cant) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  if (true) {
    ++ans;
    bool fin = false;
    for (int i = 0; i < n; i++)
      if (acnt[a[i]] != axor && b[i] == axor) {
        swap(a[i], axor);
        fin = true;
        break;
      }
    if (!fin) {
      for (int i = 0; i < n; i++)
        if (acnt[a[i]] > 0) {
          swap(a[i], axor);
          fin = true;
          break;
        }
    }
  }
  int num_mismatch = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) num_mismatch++;
  }
  cout << ans + num_mismatch << endl;
  return 0;
}
