#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
int ta[100010], tb[100010];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) scanf("%d", b + i);
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i]) break;
    if (i == n) {
      printf("0\n");
      return 0;
    }
  }
  int ans = 100010;
  for (int i = 1; i <= n; i++) ta[i] = a[i], tb[i] = b[i];
  sort(ta + 1, ta + 1 + n);
  sort(tb + 1, tb + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (ta[i] != tb[i]) break;
    if (i == n) {
      int s = 0;
      for (int j = 1; j <= n; j++) {
        if (a[j] != b[j]) s++;
      }
      ans = min(ans, s + 1);
    }
  }
  for (int i = 1; i <= n; i++) ta[i] = a[i], tb[i] = b[i];
  for (int i = 1; i <= n; i++) ta[n + 1] ^= a[i], tb[n + 1] ^= b[i];
  sort(ta + 1, ta + 2 + n);
  sort(tb + 1, tb + 2 + n);
  for (int i = 1; i <= n + 1; i++) {
    if (ta[i] != tb[i]) break;
    if (i == n + 1) {
      int s = 0;
      for (int j = 1; j <= n; j++) {
        if (a[j] != b[j]) s++;
      }
      ans = min(ans, s);
    }
  }
  if (ans == 100010)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
