#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 LL, 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 LL; at every integer point on the number line, i.e. 0,1,2,…,L0,1,2,\dots,L, 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 L  (1≤L≤10000)L\;(1 \le L \le 10000) and M  (1≤M≤100)M\;(1 \le M \le 100), where LL is the length of the road and MM is the number of intervals, separated by a single space. The following MM 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