#include <bits/stdc++.h>
int a[100010], b[100010];
int o[100010][2], p[100010][2];
int pa[100010];
int main() {
  int n;
  scanf("%d", &n);
  pa[0] = 0;
  for (int i = 1; i < 100005; i++) {
    pa[i] = i & 1 ? (i + 1) : (i - 1);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < 30; i++) {
    int sba = 0, sbb = 0;
    for (int j = 0; j < n; j++) {
      sba += a[j] >> i & 1;
      sbb += b[j] >> i & 1;
    }
    if (sba != sbb && pa[sba] != sbb) {
      printf("-1\n");
      return 0;
    }
    int x = sba & 1;
    for (int j = 0; j < n; j++) {
      int y = a[j] >> i & 1;
      int z = b[j] >> i & 1;
      if (y != z) {
        o[j][x ^ z] = 1;
      } else {
        p[j][x ^ z] = 1;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (o[i][0] && o[i][1]) {
      printf("-1\n");
      return 0;
    } else if (o[i][0] || o[i][1]) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
