#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const int max_n = 1e5 + 5;
int main() {
  int(n);
  scanf("%d", &(n));
  ;
  vector<int>(v);
  for (int i = (0); i < ((n)); ++i) {
    int(a);
    scanf("%d", &(a));
    ;
    (v).push_back(a);
  };
  vector<int>(w);
  for (int i = (0); i < ((n)); ++i) {
    int(a);
    scanf("%d", &(a));
    ;
    (w).push_back(a);
  };
  int xr = 0;
  for (int i = (0); i < (n); ++i) xr ^= v[i];
  v.push_back(xr);
  xr = 0;
  for (int i = (0); i < (n); ++i) xr ^= w[i];
  w.push_back(xr);
  n++;
  map<int, int> dupa;
  for (int i = (0); i < (n); ++i) dupa[v[i]]++;
  for (int i = (0); i < (n); ++i) dupa[w[i]]--;
  for (__typeof((dupa).begin()) i = ((dupa).begin()); i != (dupa).end(); ++i) {
    if (i->second < 0) {
      printf("-1\n");
      return 0;
    }
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    if (w[i] != v[i]) ans++;
  }
  if (ans == 0)
    printf("0\n");
  else {
    if (w[n - 1] != v[n - 1])
      printf("%d\n", ans - 1);
    else
      printf("%d\n", ans + 1);
  }
}
