gets;s=0;$<.map{|c|eval's+=(-60*%d-%d+60*%d+%d)%%1440'%c.split(/ |:/)};p s