#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
map<int, int> mp;
int n;
int a[MAXN], b[MAXN], sum;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]]++;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) sum ^= a[i];
  bool p = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (mp[b[i]]) {
      mp[b[i]]--;
    } else {
      if (b[i] == sum && p) {
        p = 0;
      } else {
        printf("%d\n", -1);
        fclose(stdin);
        fclose(stdout);
        return 0;
      }
    }
  }
  int w = n;
  for (int i = 1; i <= n; i++)
    if (a[i] == b[i]) {
      w--;
    }
  if (p)
    printf("%d\n", w + 1);
  else
    printf("%d\n", w);
}
