import strutils, sequtils let N = stdin.readline.parseInt var ttl = 0 for j in 0 ..< N: let HMHM = stdin.readLine.split var sb_ttl = 0 for i, HM in HMHM: let hm = HM.split(':').map parseInt let sgn = [-1, 1][int(i == 1)] sb_ttl += sgn * (60 * hm[0] + hm[1]) sb_ttl = (sb_ttl + 24 * 60) mod (24 * 60) ttl += sb_ttl echo ttl