#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];
  }
  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];
  for (int aPtr = 1, i = 1; i <= n; ++i, ++aPtr) {
    if (bSrt[i] != aSrt[aPtr] and bSrt[i] != aSrt[0]) {
      cout << -1 << '\n';
      return 0;
    } else if (bSrt[i] != aSrt[aPtr]) {
      --aPtr;
      aSrt[0] = -1;
    }
  }
  int ans = 0;
  if (aSrt[0] != -1) {
    ans = 2;
  } else {
    ans = 1;
  }
  bool popped = false;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i] and a[0] != b[i]) {
      ++ans;
      popped = true;
    }
  }
  if (!popped) {
    ans = 0;
  }
  cout << ans << '\n';
  return 0;
}
