#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long x = 0;
  for (int i = 0; i < n; i++) {
    x ^= a[i];
  }
  vector<long long> c, d;
  c = a;
  c.push_back(x);
  d = b;
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  int p = 0;
  long long k = -1;
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    if (p == 0 && c[i + p] != d[i]) {
      p = 1;
      k = c[i];
      if (c[i + p] != d[i]) {
        flag = 1;
        break;
      }
    } else {
      if (c[i + p] != d[i]) {
        flag = 1;
        break;
      }
    }
  }
  if (k = -1) {
    a.push_back(x);
    b.push_back(x);
  } else {
    a.push_back(x);
    b.push_back(k);
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  vector<bool> ok(n);
  int dif = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] == b[i]) {
      ok[i] = 1;
    } else {
      dif += 1;
    }
  }
  if (ok[n] == 1) {
    cout << dif + 1 << endl;
  } else {
    cout << dif << endl;
  }
  return 0;
}
