#t82. 校门外的树
校门外的树
Trees Outside the School Gate
Problem Description
Outside the gate of a school, there is a row of trees along a road of length , with adjacent trees 1 metre apart. We can think of the road as a number line: one end of the road is at position 0, the other end at position ; at every integer point on the number line, i.e. , there is a tree planted.
Some intervals of the road will be used to build a subway. These intervals are given by their start point and end point on the number line. It is known that the start and end points of any interval are integers, and intervals may overlap. Now the trees within these intervals (including the two trees at the interval endpoints) are to be removed. Your task is to compute how many trees remain on the road after all of them are removed.
Input Format
The first line contains two integers and , where is the length of the road and is the number of intervals, separated by a single space. The following lines each contain two distinct integers, separated by a single space, representing the start point and end point of an interval.
For 20% of the data, the intervals do not overlap; for the rest of the data, the intervals may overlap.
Output Format
One line containing a single integer: the number of trees remaining on the road.
Sample Input
500 3
150 300
100 200
470 471
Sample Output
298