#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (decltype(k) i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto xor_fn = [](auto x, auto y) { return x ^ y; };
void err() {
    std::cout << -1 << '\n';
    exit(0);
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u32 n; std::cin >> n;
    vec<u32> a(n), b(n);
    for (u32& x: a) std::cin >> x;
    for (u32& x: b) std::cin >> x;
    a.push_back(std::accumulate(ALL(a), u32{0}, xor_fn));
    b.push_back(std::accumulate(ALL(b), u32{0}, xor_fn));
    {
        auto a_ = a;
        auto b_ = b;
        std::sort(ALL(a_));
        std::sort(ALL(b_));
        if (a_!=b_) err();
    }
    u32 ans = 0;
    REP (i, n) ans += a.at(i)!=b.at(i);
    if (ans) ans += a.at(n)==b.at(n);
    std::cout << ans << '\n';
}
