import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInts :: IO [Integer]
readInts = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readStrings :: IO [BS.ByteString]
readStrings = BS.words <$> BS.getLine

main :: IO ()
main = do
  (n:_) <- readInts
  p <- readInts
  q <- readInts
  print $ solve (sort $ permutations [1 .. n]) p q

solve n p q = abs $ fromJust (elemIndex p n) - fromJust (elemIndex q n)