#P3740. Electoral Wall Poster Visibility

    ID: 16991 Type: Default 1000ms 256MiB

Electoral Wall Poster Visibility

Electoral Wall Poster Visibility

In Bytetown, the mayoral election is underway and all voters are allowed to post posters expressing their opinions. To manage the situation, the city committee has prepared an electoral wall for posting. The wall is a rectangular strip of length \(N\) units with each unit representing a grid cell. All posters have the same height as the wall.

Each poster is represented by two integers \(A\) and \(B\), indicating that the poster is pasted from the \(A^{th}\) cell to the \(B^{th}\) cell (both inclusive). Posters are pasted one after another, and a poster pasted later may cover part or even all of a previously posted poster.

Your task is to determine how many posters are visible on the wall after all the posters are pasted. A poster is considered visible if at least one grid cell on the wall shows it (i.e. has not been completely covered by posters pasted later).

Note: The input guarantees that \(1 \leq A \leq B \leq N\).

inputFormat

The first line contains two integers \(N\) and \(M\): the length of the wall and the number of posters.

Then follows \(M\) lines, each containing two integers \(A\) and \(B\) describing a poster posted in sequence.

outputFormat

Output a single integer representing the number of posters that are visible on the wall after all posters have been pasted.

sample

10 3
1 5
2 6
3 7
3