#include <bits/stdc++.h>
using namespace std;

int main(){
        int N; cin >> N;
        vector<int> a(N + 1):
        vector<int> b(N + 1);
        vector<int> c(N + 1);
        vector<int> d(N + 1);
        for (int i = 0; i < N; i++){
              cin >> a[i];
              c[i] = a[i];
        }
        for (int i = 0; i < N; i++){
              cin >> b[i];
              d[i] = b[i];
        }
        int x = 0;
        int y = 0;
        for (int i = 0; i < N; i++){
                x ^= a[i];
         }
         for (int i = 0; i < N; i++){
                y ^= b[i];
         }
        c[N] = x;
        d[N] = y;
        sort(c.begin(), c.end());
        sort(d.begin(), d.end());
        for (int i = 0; i < N + 1; i++){
               if (c[i] != d[i]){
                      cout << -1 << endl;
                       return 0;
               }
       }
       int ans = N;   
       for (int i = 0; i < N; i++){
              if (a[i] == b[i]){
                    ans--;
              }
       }
       cout << ans << endl;

}