#include<bits/stdc++.h>
using namespace std;
#define maxn 200008
#define int long long
int n;
int arr[maxn];
int b[maxn];
map<int,int> vis;
map<int,int> tar;
bool ok[maxn];
main(){
 //   freopen("duliu.in","r",stdin);
  //  freopen("duliu.out","w",stdout);
    scanf("%lld",&n);
    int sum=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&arr[i]);
        vis[arr[i]]++;
        sum^=arr[i];
    }
    vis[sum]++;
    int ans=1;
    int cnt=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&b[i]);
        tar[b[i]]++;
    }
    for(int i=1;i<=n;i++){
        if(arr[i]==b[i]){
            cnt++;
        }
    }
    if(vis[sum]-tar[sum]==0){
        ans--;
    }
    map<int,int>::iterator iter;
    for(iter=tar.begin();iter!=tar.end();iter++){
        if(vis[iter->first]<iter->second){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans+n-cnt<<endl;
    return 0;
}