 
#define PROB Treestrat

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
#define all(b) b.begin() , b.end()
#define mp(a, b) make_pair(a,b)
#define pb(a) push_back(a)
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define ii pair<int,int>
#define turnOff(k, i) (k&(~(1<<(i-1))))
#define isOn(k, i) (k&&(1<<i-1)?true:false)
#define pll pair<long long int , long long int>
#define ull unsigned long long int
#define ll  long long int
#ifdef  DEBUG
#define MAXN 10
#else
#define MAXN 5000020
#endif
#define MAXLG 20
#define endl '\n'
#define PI 3.141592653589793238
#define MOD (1000000007l)
#define INF (1000000007l)
#define EPS (0.00000001)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input", "r", stdin);
#endif
    int n;
    cin>>n;
    int sum = 0;
    multiset<int> aa, bb;
    set<int> total;
    int a[n],b[n];
    for (int i=0;i<n;i++) {
        cin>>a[i];
        sum = a[i] ^ sum;
        aa.insert(a[i]);
        total.insert(a[i]);
    }
    int common = 0;
    for (int i=0;i<n;i++) {
        cin>>b[i];
        if (a[i]==b[i])common++;
        bb.insert(b[i]);
        total.insert(b[i]);
    }
    bool useSum = false;
    bool poss = true;
    int diff = 0;
    for (int i : bb) {
        if (abs(aa.count(i) - bb.count(i)) != 0) {
            diff++;
        }

        if ( i == sum && bb.count(i) - aa.count(i)   ==  1) {
            useSum = true;
        }
    }
    poss = (diff == 1 && useSum) || (diff == 0);
    if (common == n) cout<<0;
    else if (!poss) cout<< -1;
    else if (useSum)cout<< n - common;
    else if (!useSum)cout<< n - common + 1;


    return 0;
}











































