#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], A2[N], B2[N];
  for (int(i) = 0; (i) < (N); (i)++) cin >> A[i];
  for (int(i) = 0; (i) < (N); (i)++) cin >> B[i];
  for (int(i) = 0; (i) < (N); (i)++) A2[i] = A[i], B2[i] = 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;
  }
  int dif = 0;
  long long nexist = 0;
  sort(A2, A2 + N);
  sort(B2, B2 + N);
  for (int(i) = 0; (i) < (N); (i)++)
    if (A2[i] != B2[i]) dif++, nexist = B2[i];
  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";
    }
  }
}
