#include <bits/stdc++.h>
using namespace std;
int n, ch[100005], sh[100005], ans, sum;
map<int, int> mp;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sh[i]);
    sum ^= sh[i];
    mp[sh[i]]++;
  }
  mp[sum]++;
  int tmp = mp[sum];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ch[i]);
    mp[ch[i]]--;
    if (mp[ch[i]] < 0) {
      ans = -999999999;
    }
    if (sh[i] != ch[i]) ans++;
  }
  if (ans < 0)
    printf("-1");
  else {
    if (mp[sum] > 0) {
      if (ans == 0)
        printf("0");
      else {
        if (ans == 1 || ans == 2)
          printf("%d", ans);
        else
          printf("%d", ans + 1);
      }
    } else {
      printf("%d", ans);
    }
  }
}
