#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], b[N], ans, tot, flag = 1;
multiset<int> sta, stb;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tot ^= a[i];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (a[i] != b[i]) {
      sta.insert(a[i]);
      stb.insert(b[i]);
      ans++;
    }
  }
  for (multiset<int>::iterator it = stb.begin(); it != stb.end(); it++) {
    if (flag && (*it) == tot) {
      flag = 0;
      stb.erase(*it);
    } else {
      if (sta.find(*it) != sta.end()) {
        sta.erase(sta.find(*it));
      } else {
        puts("-1");
        return 0;
      }
    }
  }
  printf("%d", ans + !sta.empty());
  return 0;
}
