#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  int x = 0;
  for (int i = 0; i < n; ++i) x ^= a[i];
  multiset<int> sta, stb;
  set<int> st;
  for (int i = 0; i < n; ++i) {
    sta.insert(a[i]);
    stb.insert(b[i]);
    st.insert(a[i]);
    st.insert(b[i]);
  }
  int from, to, d1 = 0, d2 = 0;
  for (auto t : st) {
    int p = sta.count(t);
    int q = stb.count(t);
    if (abs(p - q) > 1) {
      cout << -1 << endl;
      return 0;
    }
    if (p == q - 1) {
      d1++;
      to = t;
    }
    if (p - 1 == q) {
      d2++;
      from = t;
    }
  }
  if (d1 == 0 && d2 == 0) {
    if (sta.count(x) == 0) {
      cout << -1 << endl;
      return 0;
    }
    int ans = 1;
    for (int i = 0; i < n; ++i) {
      ans += (a[i] != b[i]);
    }
    cout << ans << endl;
    return 0;
  }
  if (d1 == 1 && d2 == 1) {
    if (x != to) {
      cout << -1 << endl;
      return 0;
    }
    bool gd = false;
    for (int i = 0; i < n; ++i) {
      if (a[i] == from && b[i] == to) {
        a[i] = to;
        gd = true;
        break;
      }
    }
    if (!gd) {
      for (int i = 0; i < n; ++i) {
        if (a[i] == from) {
          a[i] = to;
          break;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) ans += (a[i] != b[i]);
    cout << ans << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
