#include <bits/stdc++.h>
using namespace std;
int n, a[100009], b[100009], c1, c2;
vector<int> x, y;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c1 ^= a[i];
    x.push_back(a[i]);
  }
  x.push_back(c1);
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    c2 ^= b[i];
    y.push_back(b[i]);
  }
  y.push_back(c2);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if (x != y) {
    cout << "-1" << endl;
    return 0;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) cnt++;
  }
  if (cnt == 0)
    cout << "0" << endl;
  else if (c1 != c2)
    cout << cnt << endl;
  else
    cout << cnt + 1 << endl;
  return 0;
}
