#include <bits/stdc++.h>
using namespace std;
const int MAX = 100009;
int a[MAX];
int b[MAX];
int main() {
  int n;
  cin >> n;
  int xa = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    xa ^= a[i];
  }
  a[n] = xa;
  int xb = 0;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    xb ^= b[i];
  }
  b[n] = xb;
  int fl = 0, X = 0;
  if (a[n] == b[n]) fl = 1;
  for (int i = 0; i <= n; i++) {
    if (a[i] != b[i]) X++;
  }
  sort(a, a + n + 1);
  sort(b, b + n + 1);
  for (int i = 0; i <= n; i++) {
    if (a[i] != b[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (X == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (fl) {
    cout << X + 1 << endl;
  } else
    cout << X - 1 << endl;
}
