n = int(input())
def toSeconds(l):
h, m, s = l
return h * 60 * 60 + m * 60 + s
cnt = [0] * (24 * 60 * 60)
for i in range(n):
l = list(map(int, input().split()))
begin = toSeconds(l[:3])
end = toSeconds(l[3:])
cnt[begin] += 1
cnt[end] -= 1
for i in range(1, 24 * 60 * 60):
cnt[i] += cnt[i - 1]
ans = 0
for i in range(8 * 60 * 60, 20 * 60 * 60):
if cnt[i] == 0:
ans += 1
print(ans)