#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
int main(void) {
  long long N;
  cin >> N;
  long long A[N], B[N];
  for (int(i) = 0; (i) < (N); (i)++) cin >> A[i];
  for (int(i) = 0; (i) < (N); (i)++) cin >> B[i];
  bool check = true;
  for (int(i) = 0; (i) < (N); (i)++)
    if (A[i] != B[i]) check = false;
  if (check) {
    cout << 0 << "\n";
    return 0;
  }
  multiset<long long> A2, B2;
  for (int(i) = 0; (i) < (N); (i)++) A2.insert(A[i]), B2.insert(B[i]);
  int dif = 0;
  long long nexist = 0;
  while (!A2.empty()) {
    auto itr = A2.begin();
    long long cmp1 = A2.count(*itr), cmp2 = B2.count(*itr);
    dif += llabs(cmp1 - cmp2);
    A2.erase(*itr);
    B2.erase(*itr);
    auto ex = B2.begin();
    nexist = *ex;
  }
  if (dif > 1) {
    cout << -1 << "\n";
    return 0;
  }
  if (dif == 0) {
    int count = 1;
    for (int(i) = 0; (i) < (N); (i)++)
      if (A[i] != B[i]) count++;
    cout << count << "\n";
  } else {
    long long xorn = 0;
    for (int(i) = 0; (i) < (N); (i)++) xorn = xorn ^ A[i];
    if (xorn != nexist)
      cout << -1 << "\n";
    else {
      int count = 0;
      for (int(i) = 0; (i) < (N); (i)++)
        if (A[i] != B[i]) count++;
      cout << count << "\n";
    }
  }
}
