#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int nw, n, dif, ans, a[N], b[N];
map<int, int> vis, viss;
int main() {
  nw = ans = 0;
  dif = -1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), vis[a[i]]++, viss[a[i]]++;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (vis[b[i]] == 0) {
      if (dif != -1)
        return puts("-1"), 0;
      else
        dif = b[i];
    } else
      vis[b[i]]--;
  }
  for (int i = 1; i <= n; i++) nw ^= a[i];
  if (dif != -1) {
    if (dif != nw)
      return puts("-1"), 0;
    else {
      for (int i = 1; i <= n; i++) ans += (a[i] != b[i]);
      printf("%d\n", ans);
    }
  } else {
    bool flag = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] != b[i]) {
        ans++;
        if (nw == b[i]) flag = 1;
      }
    }
    if (ans) {
      if (flag == 0) ans++;
    }
    printf("%d\n", ans);
  }
}
