#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const int mod = 1e9 + 7;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  int n;
  cin >> n;
  int a[n], b[n], x = 0, cnt = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    x ^= a[i];
  }
  for (int i = 0; i < (int)(n); i++) {
    cin >> b[i];
    if (a[i] != b[i]) cnt++;
  }
  map<int, int> mp;
  for (int i = 0; i < (int)(n); i++) {
    mp[a[i]]++;
    mp[b[i]]--;
  }
  int sum = 0;
  for (auto i : mp) {
    sum += abs(i.second);
  }
  if (sum == 0) {
    cout << cnt + 1 << endl;
    return 0;
  }
  mp[x]++;
  sum = 0;
  for (auto i : mp) {
    sum += abs(i.second);
  }
  if (sum == 1)
    cout << cnt << endl;
  else
    cout << -1 << endl;
  return 0;
}
