#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
int a[maxn], b[maxn], n, tmp, ar[maxn], br[maxn];
bool equal(int a[], int b[]) {
  for (int i = 0; i <= n; i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    tmp ^= a[i];
    ar[i] = a[i];
  }
  a[0] = tmp;
  ar[0] = tmp;
  tmp = 0;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    tmp ^= b[i];
    br[i] = b[i];
  }
  b[0] = tmp;
  br[0] = tmp;
  sort(a, a + n + 1);
  sort(b, b + n + 1);
  if (!equal(a, b)) return cout << -1 << endl, 0;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (ar[i] != br[i]) ans++;
  if (ar[0] == br[0] && ans > 0) ans++;
  cout << ans << endl;
}
