#include <bits/stdc++.h>
using namespace std;
int n;
int a[100009], b[100009];
int ans;
bool mach, mm;
int s;
map<int, int> mp;
int main() {
  scanf("%d", &n);
  for (int j = 1; j <= n; j++) {
    scanf("%d", &a[j]);
    s ^= a[j];
  }
  for (int j = 1; j <= n; j++) scanf("%d", &b[j]);
  mp[s]++;
  for (int j = 1; j <= n; j++)
    if (a[j] != b[j]) {
      mp[a[j]]++;
      ans++;
    }
  for (int j = 1; j <= n; j++)
    if (a[j] != b[j]) {
      if (mp[b[j]] == 0) {
        printf("-1");
        return 0;
      }
      mp[b[j]]--;
    }
  printf("%d", ans);
  return 0;
}
