#include <bits/stdc++.h>
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
void print(int x) {
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 100007;
int n, a[maxn], b[maxn];
std::map<int, int> mp;
std::map<int, int> rmp;
int st = 0;
struct node {
  int x, rk;
  bool operator<(const node& a) const { return x < a.x; }
} t[maxn];
int k[maxn];
int p[maxn];
int tot = 0;
std::map<int, int> rrk;
int sum = 0, tmp = 0, cnt = 0;
int calc() {
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i] && a[i] == st) ans -= 1;
  }
  return ans;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read(), mp[a[i]]++, sum ^= a[i];
  for (int i = 1; i <= n; ++i) {
    b[i] = read();
    rmp[b[i]]++;
    if (!mp[b[i]]) ++tot, tmp = b[i];
    if (a[i] != b[i]) cnt++;
    st ^= b[i];
  }
  if (tot >= 2) {
    puts("-1");
    return 0;
  }
  if (tot <= 1) {
    if (tot) {
      if (sum != tmp) {
        puts("-1");
        return 0;
      } else {
        print(cnt / 2 * 3 + calc() - 1);
        putchar('\n');
      }
    } else
      print(cnt / 2 * 3 + calc());
  }
  return 0;
}
