#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1ll << 61;
struct edge {
  long long to, cost;
};
long long a[100006], b[100006];
long long sa[100006], sb[100006];
long long XA, XB;
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n; i++) {
    sa[i] = a[i];
    sb[i] = b[i];
    sa[n] ^= a[i];
    sb[n] ^= b[i];
  }
  XA = sa[n], XB = sb[n];
  sort(sa, sa + n + 1);
  sort(sb, sb + n + 1);
  for (long long i = 0; i < n + 1; i++) {
    if (sa[i] != sb[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long cnt = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] != b[i]) cnt++;
  if (cnt == 0)
    cout << 0 << endl;
  else {
    if (XA == XB)
      cout << cnt + 1 << endl;
    else
      cout << cnt << endl;
  }
}
