Problem G
Fire
Languages
en
is
In the old Baltic religion, it is important to have a holy fire burning. A priest called krivis is responsible for protecting it from extinguishing. He has many trustworthy helpers called vaidilutės, and wants to create a schedule for them to stoke and protect the fire. He has to ensure that the fire is always maintained by some vaidilutė.
Krivis has his own time measurement system, where
each day has
Krivis asked you to choose some vaidilutės
and arrange shifts for them. A chosen vaidilutė must
start her shift not earlier than time
Handing things over from one vaidilutė to the next increases the risk of the fire extinguishing. Because of this, you want to minimize the number of times this happens during the day and will arrange a schedule where the smallest possible number of vaidilutės is needed.
Task
Calculate the minimum number of vaidilutės that you need to choose, such that the holy fire is maintained at all times.
Input
The first line contains two integers
Then
Output
Output one integer - the minimum number of
vaidilutės you need to choose. If it is impossible to
choose the vaidilutės according to the requirements,
output
Constraints
-
-
-
(for all ) -
(for all )
Subtasks
No. |
Points |
Additional constraints |
1 |
14 |
|
2 |
17 |
|
3 |
9 |
|
4 |
13 |
For all vaidilutės, |
5 |
21 |
For each vaidilutė, the time interval from
time |
6 |
26 |
No additional constraints. |
Examples
In the first example you can choose the 1-st, 2-nd and 4-th vaidilutės and arrange their shifts as follows:
-
1-st vaidilutė works from the 10-th minute until the 30-th minute.
-
2-nd vaidilutė works from the 30-th minute until the 70-th minute.
-
4-th vaidilutė works from the 70-th minute until the 10-th minute on the following day.
In the second example it is impossible to make a schedule since there is only one vaidilutė and she cannot work the whole day.
Sample Input 1 | Sample Output 1 |
---|---|
4 100 10 30 30 70 20 40 60 20 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
1 100 30 40 |
-1 |