    }
	for (int i = 1; i <= n; i ++) tar[n+1] ^= tar[i];
	if (tar[n+1] != ori[n+1]) ans -= 2;
    for (int i = 1; i <= n+1; i ++)
    {
        a[i] = id[ori[i]];
        b[i] = id[tar[i]];
		vec[b[i]].push_back(i);
    }
	for (int i = 1; i <= kind; i ++)
	{
//		printf("kind %d:\n", i);
		for (int j = 0; j < vec[i].size(); j ++)
		{
//			printf("%d ", vec[i][j]);
			if (j > 0) unite(vec[i][j-1], vec[i][j]);
		}
//		printf("\n");
	}
}
int main()
{
	n = in();
	for (int i = 1; i <= n; i ++) 
    {
        tot[i] = ori[i] = in();
        xsum ^= ori[i];
    }
    ori[n+1] = tot[n + 1] = xsum;
	for (int i = 1; i <= n; i ++) tar[i] = in();
    // /*
    if (judge() == false) 
    {
        printf("-1");
        return 0;
    }
    init();
    for (int i = 1; i <= n+1; i ++)
        if (a[i] == b[i]) vis[i] = true;
		else ans ++;
	for (int i = 1; i <= n+1; i ++)
	{
		unite(i, vec[a[i]][0]);
	}
    for (int i = 1; i <= n+1; i ++)
    {
        if (vis[i]) continue;
        if (fa[i] == i) 
		{
			ans ++;
//			printf("[%d]\n", i);
		}
    }
    cout << ans << endl;
    // */
	return 0;
}
/*
 
5
4 1 3 4 2
1 4 2 3 4
 
6
233 2333 666 233 1234 888 (3117)
666 3117 233 233 888 2333 (1234)
 
6
233 2333 666 888 1234 233
666 3117 233 233 888 2333
*/
 
