#P1047. Tree Removal on a Road
Tree Removal on a Road
Tree Removal on a Road
There is a road of length \(l\) meters with trees planted at every integer point from \(0\) to \(l\). Some regions along the road are designated for metro construction, and each region is specified by its starting and ending points (both integers). The trees located at both endpoints of every region are removed. Note that regions may overlap; if so, the overlapping trees are removed only once. Your task is to calculate the number of trees that remain on the road after removing all trees in the designated regions.
inputFormat
The first line contains two integers \(l\) and \(n\): the length of the road and the number of intervals, respectively. Each of the following \(n\) lines contains two integers \(a\) and \(b\) (with \(0 \le a \le b \le l\)) representing an interval \([a, b]\).
outputFormat
Output a single integer indicating the number of trees remaining on the road.
sample
10 2
2 5
7 8
5