#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,s,a[MAXN],b[MAXN];
map<int,int> mpa,mpb;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        s^=a[i];mpa[a[i]]++;
    }
    mpa[s]++;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        mpb[b[i]]++;
    }
    for(auto p:mpb)
    {
        if(mpa[p.F]<mpb[p.F])
        {
            puts("-1");
            return 0;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++) if(a[i]!=b[i]) cnt++;
    if(cnt==0) {puts("0"); return 0;} else 
    {
        if(mpa[s]==mpb[s]) printf("%d\n",cnt);
        else printf("%d\n",cnt+1);
    }
    return 0;
}

