PivotOJ

Event Hopping

시간 제한: 1000ms메모리 제한: 512MB출처: BOI 2022BOJ 25260

문제

What a strange coincidence! After having determined the most valuable contemporary art collection, you noticed that it is apparently located somewhere near Lübeck. Since you don’t know its exact location, you want to gather more information. Luckily, on the day you arrive for this year’s BOI, the local art community hosts NN events about contemporary art. This seems to be just the opportunity you were waiting for.

To plan your visit of these events, you numbered them from 11 to NN with the ii-th event starting at time SiS_i and ending at time EiE_i. You want to start your visit by attending some event ss and finish your visit at some event ee. As long as you are not attending event ee, you will always attend your current event until the end* and then immediately switch to a different event that is currently running. This means that you can switch from event ii to event jj if and only if S_j ≤ E_i ≤ E_j.

Obviously, switching events too frequently would make you look suspicious. Thus, you want to determine the minimum number of event switches necessary if you start at event ss and finish at ee. Moreover, since you do not yet know when you will arrive in Lübeck and when you will have to leave for the BOI registration in the evening, you want to determine this for QQ different pairs of starting and ending events ss and ee.


* It would be rude to leave earlier—though nobody will complain about you being late as you are obviously an important and busy art critic.

입력

The first line of input contains two integers, the number of events NN and the number of pairs of events QQ for which you want to determine the minimum number of event switches.

Then, NN lines follow describing the events. The ii-th of these lines contains two integers SiS_i and EiE_i, the starting and ending time of event ii.

Then, QQ lines follow describing the queries. The ii-th of these lines contains two integers sis_i and eie_i, meaning that you want to determine the minimum number of event switches necessary if you want to start at event sis_i and end your visit at event eie_i.

출력

Your program should output QQ lines. The ii-th of these lines should consist of an integer, the minimum number of event switches necessary if you start at event sis_i and end your visit at event eie_i, or the string impossible if there is no way to achieve this.

힌트

In the first example, it is possible to start at event 11 and end at event 44 by switching from event 11 to event 55 and then to event 44, resulting in two event switches. However, there is no way to start at event 33 and end at event 22 because event 22 ends before event 33.

예제

예제 1

입력
5 2
1 3
2 4
4 7
7 9
3 7
1 4
3 2
출력
2
impossible

예제 2

입력
8 5
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
1 7
2 4
3 3
5 8
출력
3
4
impossible
0
impossible
코드를 제출하려면 로그인하세요.