import           Data.List
p (Just x) = print x
main = do
        n <- readLn :: IO Int
        p <- map read . words <$> getLine :: IO [Int]
        q <- map read . words <$> getLine :: IO [Int]
        p $ elemIndex q $ sort $ permutations p