#T816. 校门外的树
校门外的树
Description
Outside the gate of a certain school, there is a row of trees along a road of length L, with each adjacent pair of trees spaced 1 meter apart. We can consider the road as a number line, where one end of the road is at position 0 on the number line, and the other end is at position L. Every integer point on the number line, i.e., 0, 1, 2, ..., L, has a tree planted on it.
Due to the construction of a subway, some sections of the road will be used. These sections are represented by their starting and ending points on the number line. It is known that the coordinates of the starting and ending points of any section are integers, and the sections may overlap. Now, all the trees within these sections (including the trees at the endpoints) must be removed. Your task is to calculate how many trees will remain on the road after the removal.
Input Format
The first line contains two integers, L (1 ≤ L ≤ 10000) and M (1 ≤ M ≤ 100), separated by a space. L represents the length of the road, and M represents the number of sections. The next M lines each contain two distinct integers separated by a space, representing the starting and ending coordinates of a section.
For 20% of the data, the sections do not overlap; for the remaining data, overlapping sections may occur.
Output Format
The output consists of a single line containing one integer, representing the number of remaining trees on the road.
```input1 500 3 150 300 100 200 470 471```output1
298
翻译结果
CodesOnline
(注:根据提供的简短文本"CodesOnline",这是一个专有名词或品牌名称,通常保持原样不翻译。因此,直接保留英文形式,符合技术领域术语的通用处理方式。)