import Data.List
main = do
  n <- readLn
  ps <- map read . words <$> getLine
  qs <- map read . words <$> getLine
  let a = sort $ permutations [1..n]
      r = length $ takeWhile (<= ps) a
      t = length $ takeWhile (<= qs) a
  print $ abs(r - t)
  
