import Control.Monad main = do n <- readLn hms <- map (map readTime . words) <$> replicateM n getLine print $ sum (map hours hms) readTime s = 60 * read h + read m where (h,(':':m)) = break (==':') s hours [t1,t2] = mod (t2 - t1) 1440