Competitions
Sweeping line
Fill the line
n segments are painted on the line. The coordinates of the left and right ends of each segment li
and ri
are known. Find the length of the colored part of the line.
Input
The first line contains the number n (1 ≤ n ≤ 15000), the following n lines contains the pair of integers li
and ri
(-109
≤ li
≤ ri
≤ 109
).
Output
Print the length of the colored part of the line.
Input example #1
5 6 8 1 2 0 3 7 9 2 4
Output example #1
7