#include <bits/stdc++.h>
using namespace std;
vector<int> get(vector<int> a, vector<int> b) {
  multiset<int> kek;
  for (int i = 0; i < a.size(); i++) kek.insert(a[i]);
  for (int i = 0; i < b.size(); i++) {
    if (!kek.count(b[i])) continue;
    kek.erase(kek.find(b[i]));
  }
  vector<int> res;
  if (!kek.size()) return {};
  for (auto it = kek.begin(); it != kek.end(); it++) {
    res.push_back(*it);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  int X = 0;
  for (int i = 0; i < n; i++) X ^= a[i];
  vector<int> t = get(a, b), q = get(b, a);
  if (t.size() >= 2) {
    cout << -1;
    return 0;
  }
  if (t.size() == 0) {
    int mis_pos = 0;
    for (int i = 0; i < n; i++)
      if (a[i] != b[i]) mis_pos++;
    if (mis_pos == 0) {
      cout << 0;
      return 0;
    }
    cout << mis_pos + 1 << endl;
    return 0;
  }
  if (q[0] != X) {
    cout << -1;
    return 0;
  }
  int mis_pos = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) mis_pos++;
  cout << mis_pos;
}
