# -*- coding: utf-8 -*- import datetime # 1. 入力情報取得. N = int(input()) ans = 0 for i in range(N): I = input() I = I.split() # print(I) # 寝た時刻(D日H時M分) D = 1 H = int(I[0].split(":")[0]) M = int(I[0].split(":")[1]) # 起きた時刻(d日h時m分) d = 1 h = int(I[1].split(":")[0]) m = int(I[1].split(":")[1]) # print("D=" + str(D) + " H=" + str(H) + " M=" + str(M) + " d=" + str(d) + " h=" + str(h) + " m=" + str(m)) # 2. 日付データと見て差分を計算. # pythonで日時の差分を秒単位で出す方法. # https://qiita.com/puriketu99/items/568befc13510ee4d587f if H > h: d += 1 fTime = datetime.datetime(2019, 2, D, H, M, 0) lTime = datetime.datetime(2019, 2, d, h, m, 0) delta = (lTime - fTime).total_seconds() / 60.0 ans = ans + int(delta) # 3. 出力. print(ans)