package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

type IOTp struct {
	iBuffer []byte
	iPos int
}
func (this *IOTp) GetChar() byte {
	res:=this.iBuffer[this.iPos]
	this.iPos++
	return res
}
func (this *IOTp) ReadInt() int {
	res:=0
	k:=1
	for ch:=this.iBuffer[this.iPos]; !(ch>='0' && ch<='9'); ch=this.iBuffer[this.iPos]{
		if ch=='-' {
			k=-1
		}
		this.iPos++
	}
	for ch:=this.iBuffer[this.iPos]; ch>='0' && ch<='9'; ch=this.iBuffer[this.iPos]{
		res=res*10+int(ch-'0')
		this.iPos++
	}
	res*=k
	return res
}
func NewIOTp() *IOTp {
	now:=new(IOTp)
	//inputFile,_:=os.Open("in.txt")
	inputFile:=os.Stdin
	now.iBuffer,_=ioutil.ReadAll(inputFile)
	now.iBuffer=append(now.iBuffer, '\n')
	now.iPos=0
	return now
}
var cin *bufio.Reader
var cout *bufio.Writer
const MAXN=100000
func main() {
	IO:=NewIOTp()
	cout=bufio.NewWriter(os.Stdout)
	n:=IO.ReadInt()
	var a,b [MAXN+10]int
	for i:=1; i<=n; i++ {
		a[i]=IO.ReadInt()
	}
	for i:=1; i<=n; i++ {
		b[i]=IO.ReadInt()
	}
	for _,v:=range a[1:n+1] {
		a[n+1]^=v
	}
	for _,v:=range b[1:n+1] {
		b[n+1]^=v
	}
	m:=make(map[int]int)
	for _,v:=range a[1:n+2] {
		m[v]++
	}
	for _,v:=range b[1:n+2] {
		m[v]--
	}
	for _,v:=range m {
		if v!=0 {
			fmt.Println(-1)
			return;
		}
	}
	ans:=0
	for i:=range a[1:n+2] {
		if a[i]!=b[i] {
			ans++
		}
	}
	if a[n+1]==b[n+1] && ans!=0 {
		ans++
	}
	fmt.Println(ans)
	cout.Flush()
}
