n = int(input()) time = 0 for i in range(n): bed_in, bed_out = input().split(' ') h, m = map(int, bed_in.split(':')) bed_in = 60 * h + m h, m = map(int, bed_out.split(':')) bed_out = 60 * h + m time += bed_out - bed_in if bed_in <= bed_out else 1440 - (bed_in - bed_out) print(time)