import Data.List

main = do
  n <- readLn :: IO Int
  ps <- map read . words <$> getLine :: IO [Int]
  qs <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show (ans n ps qs)

ans :: Int -> [Int] -> [Int] -> Int
ans n ps qs = abs $ (f n ps) - (f n qs)

f :: Int -> [Int] -> Int
f n ps = g $ elemIndex ps (sort (permutations [1..n]))

g :: Maybe Int -> Int
g (Just n) = n
g Nothing = 0
