n = gets.to_i

d = gets.chomp.split.map(&:to_i)
dd = gets.chomp.split.map(&:to_i)

pry = []

i = 1

while i <= n
	pry << i
	i += 1
end

res = []
count = 0

pry.permutation(n) do |item|
	count += 1
	if item[0..n-1] == d || item[0..n-1] == dd
		res << count
	end
end

puts res.max - res.min