a = gets.to_i
aa = []
ar = []
for num in 1..a do
  aa << num
end
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
aa.permutation do |x|
  ar << x
end

bn = ar.index(b) + 1
cn = ar.index(c) + 1
p (bn - cn).abs 