#include <bits/stdc++.h>
using namespace std;
long long const MAXN = 1e5 + 8;
long long const INF = 1e12 + 8;
long long const delta = 1000000007;
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n], b[n], x1 = 0, x2 = 0;
  vector<long long> v1, v2;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    x1 ^= a[i];
    v1.push_back(a[i]);
    ;
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    x2 ^= b[i];
    v2.push_back(b[i]);
    ;
  }
  v1.push_back(x1);
  ;
  v2.push_back(x2);
  ;
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (v1 != v2) return cout << -1, 0;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] != b[i]) ans++;
  }
  if (!ans) return cout << 0, 0;
  sort(a, a + n);
  sort(b, b + n);
  long long p = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] != b[i]) p = 1;
  }
  if (p) return cout << ans, 0;
  cout << ans + 1;
  return 0;
}
