#include <bits/stdc++.h>
const int MAX_DFS_NUM = 15;
int a[100005], b[100005];
int ans = MAX_DFS_NUM;
int cur[100005];
int xor_ans, n;
void DFS(int floor) {
  if (floor >= ans) return;
  int cur_xor_ans = xor_ans, temp, xs_num = 0;
  for (int i = 1; i <= n; ++i) {
    if (cur[i] == b[i]) {
      ++xs_num;
      continue;
    }
    if (cur[i] == xor_ans) continue;
    xor_ans ^= cur[i];
    xor_ans ^= cur_xor_ans;
    temp = cur[i];
    cur[i] = cur_xor_ans;
    DFS(floor + 1);
    cur[i] = temp;
    xor_ans = cur_xor_ans;
  }
  if (xs_num == n) ans = floor;
}
int main() {
  scanf("%d", &n);
  int i;
  bool is_all_01 = true;
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (i == 1)
      xor_ans = a[i];
    else
      xor_ans ^= a[i];
    if (a[i] != 0 && a[i] != 1) is_all_01 = false;
  }
  for (i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    if (b[i] != 0 && b[i] != 1) is_all_01 = false;
  }
  if (is_all_01) {
    int turn0 = 0, turn1 = 0;
    for (i = 1; i <= n; i++) {
      if (a[i] ^ b[i]) {
        if (a[i])
          ++turn1;
        else
          ++turn0;
      }
    }
    if (xor_ans) {
      if (turn0 > (turn1 + 1) || turn0 < turn1) {
        printf("-1");
        return 0;
      }
    } else {
      if (turn0 + 1 < turn1 || turn0 > turn1) {
        printf("-1");
        return 0;
      }
    }
    printf("%d", turn0 + turn1);
    return 0;
  }
  for (i = 1; i <= n; ++i) cur[i] = a[i];
  if (n <= 10) {
    DFS(0);
    if (ans == MAX_DFS_NUM)
      printf("%d", -1);
    else
      printf("%d", ans);
  }
  printf("-1");
  return 0;
}
