import Control.Monad import Data.List main = do n <- readLn ws <- replicateM n $ words <$> getLine let ws' = map (\[x, y] -> (getMin x, getMin y)) ws print $ sum $ map sleep ws' getMin time = (read h) * 60 + (read m) where (h,(':':m)) = break (== ':') time sleep (minS, minE) = if t < 0 then 60 * 24 + t else t where t = minE - minS