COCI '25 Contest 5 #1 Škare
View as PDF
Wanting to perfect his scissors using skills, Fran came up with a new exercise. He got himself a paper strip of length centimetres and, of course, a pair of scissors. He also asked Lana to assist him for the exercise.
Lana will give Fran instructions of the following type: "Cut the
-th strip at
centimetres". At the beginning, Fran has one strip. After the first action, he will have two strips: the first strip
centimetres long, and the second one
centimetres long (the remainder of the original strip). After that, Fran will cut either the first or the second strip - depending on Lana's instruction. Each time he cuts a strip, the two new pieces replace the original strip in the sequence.
More formally, suppose Fran has m strips of lengths . If Lana tells him to cut the
-th strip at
centimetres, the new sequence of strip lengths becomes:
.
After performing all cuts, he and Lana want to verify the cutting process. One way to do that is to count how many distinct strip lengths there are at the end. Your task is to compute this number.
Input Specification
The first line contains two natural numbers and
, the length of the original strip and the number of instructions Lana gives Fran.
Each of the following k lines contains two natural numbers and
, where
is the length of the
-th strip at that moment
. These numbers indicate that Fran should cut the
-th strip at
centimetres (counting strips from the beginning).
Output Specification
In the first and only line, write one number - the number of distinct strip lengths that Fran will be left with after he performs all the cuttings.
Constraints
| Subtask | Points | Constraints |
|---|---|---|
| No additional constraints. |
Sample Input 1
5 1
1 2
Sample Output 1
2
Explanation for Sample Output 1
Sample Input 2
6 2
1 4
1 2
Sample Output 2
1
Explanation for Sample Output 2
Sample Input 3
10 3
1 2
2 3
3 2
Sample Output 3
2
Comments