N = gets.to_i

a_list = gets.strip.split(/ /).collect{|n| n.to_i}
b_list = gets.strip.split(/ /).collect{|n| n.to_i}

def check(a_list, b_list)
	xor = 0
	a_list.each{|a|
		xor ^= a
	}
	
	s_a_list = a_list.sort
	s_b_list = b_list.sort
	
	j = 0
	xor_used = false
	skipped = nil
	s_b_list.each{|x|
		if !xor_used && xor == x
			xor_used = true
		else
			if x == s_a_list[j]
				j += 1
			elsif skipped == nil
				skipped = s_a_list[j]
				j += 1
				if x == s_a_list[j]
					j += 1
				else
					return nil
				end
			else
				return nil
			end
		end
	}
	return [xor, skipped]
end

if result = check(a_list, b_list)
	xor, skipped = result
	if skipped
		count = 1
	else
		count = 0
	end
	N.times{|i|
		if a_list[i] != b_list[i]
			count += 1
		end
	}
	puts count
else
	puts "-1"
end

