#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int n;
int a[MaxN], b[MaxN], aSrt[MaxN], bSrt[MaxN];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[0] ^= a[i];
    aSrt[i] = a[i];
  }
  bool uniqueXor = true;
  for (int i = 1; i <= n; ++i) {
    if (a[0] == a[1]) {
      uniqueXor = false;
      break;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    bSrt[i] = b[i];
  }
  sort(aSrt + 1, aSrt + n + 1);
  sort(bSrt + 1, bSrt + n + 1);
  aSrt[0] = a[0];
  bool bad1 = false;
  for (int aPtr = 1, i = 1; i <= n; ++i, ++aPtr) {
    if (bSrt[i] != aSrt[aPtr] and bSrt[i] != aSrt[0]) {
      bad1 = true;
    } else if (bSrt[i] != aSrt[aPtr]) {
      --aPtr;
      aSrt[0] = -1;
    }
  }
  bool bad2 = false;
  if (bad1 == true) {
    aSrt[0] = a[0];
    for (int aPtr = 1, i = 1; i <= n; ++i, ++aPtr) {
      if (bSrt[i] != aSrt[aPtr] and bSrt[i] != aSrt[0]) {
        bad2 = true;
      } else if (bSrt[i] != aSrt[aPtr]) {
        aSrt[0] = -1;
      }
    }
  }
  if (bad1 == bad2 and bad1 == true) {
    cout << -1 << '\n';
    return 0;
  }
  int ans = 0;
  bool equal = true;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) {
      equal = false;
    }
  }
  if (equal) {
    cout << 0 << '\n';
    return 0;
  }
  bool popped = false;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i] and b[i] == a[0]) {
      ++ans;
      a[i] = a[0];
      popped = true;
      break;
    }
  }
  if (popped == false) {
    ans = 2;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) {
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}
