e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
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 (1n15000), the following n lines contains the pair of integers li and ri (-109liri109).

Output

Print the length of the colored part of the line.

prb1070.gif

Time limit 1 second
Memory limit 128 MiB
Input example #1
5
6 8
1 2
0 3
7 9
2 4
Output example #1
7