#include <bits/stdc++.h>
using namespace std;
int A[100000];
int B[100000];
int n, m;
map<int, int> p;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i], p[A[i]]++;
  int d = -1;
  for (int i = 0; i < n; i++) {
    cin >> B[i];
    if (A[i] != B[i]) m++;
    p[B[i]]--;
    if (p[B[i]] < 0) {
      if (d != -1) {
        cout << -1;
        return 0;
      } else
        d = B[i];
    }
  }
  int s = 0;
  for (int i = 0; i < n; i++) s ^= A[i];
  if (d == -1 || s == d) {
    cout << m * 2 - 2;
  } else
    cout << -1 << endl;
  return 0;
}
