import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;

    int x = 0;
    foreach (a; A) x ^= a;
    N += 1;
    A ~= x;

    int[int] cnta;
    int[int] cntb;

    foreach (a; A) cnta[a] += 1;
    foreach (b; B) cntb[b] += 1;
    //cnta[x] += 1;

    int missing = -1;
    foreach (b; B) {
        if (!(b in cnta)) {
            if (missing != -1 || cnta[b] > 1) {
                writeln(-1);
                return;
            }
        } else if (cnta[b] - cntb[b] == 1) {
            if (missing != -1) {
                writeln(-1);
                return;
            }
            missing = b;
        }
    }

    B ~= missing;

    int ans = 0;
    foreach (i; 0..N-1) if (A[i] != B[i]) ans += 1;
    writeln(ans + A[N-1] == B[N-1]);
}


class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}
