#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n, a[N], b[N];
map<int, int> fi, se;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int all = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    fi[a[i]]++;
    all ^= a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    se[b[i]]++;
  }
  long long diff = 0, place = 0;
  long long ans = 0;
  for (auto x : se)
    if (fi.count(x.first))
      diff += abs(x.second - fi[x.first]);
    else {
      diff += x.second;
      place = 1;
      if (all ^= x.first) return cout << -1, 0;
    }
  if (diff > 1) return cout << -1, 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] != b[i]) ans++;
  if (ans == 0) return cout << ans, 0;
  cout << ans + (place ^ 1);
  return 0;
}
