import Data.List main = do getLine ws <- map read . words <$> getLine getLine bs <- map read . words <$> getLine print (shimashima ws bs) shimashima :: [Int] -> [Int] -> Int shimashima ws bs = max (length (pile [] ws' bs')) (length (pile [] bs' ws')) where (ws',bs') = (sortBy (flip compare) ws, sortBy (flip compare) bs) pile s [] _ = s pile [] (x:xs) yys = pile [x] yys xs pile s (x:xs) yys | head s <= x = pile s xs yys | otherwise = pile (x:s) yys xs