require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
# N = gets_i

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end


N = gets_i
p_list = gets_i_list
q_list = gets_i_list

patterns = p_list.permutation(N).to_a.sort

puts (patterns.index(p_list) - patterns.index(q_list)).abs