Message
Message
h>
#define int long long
using namespace std;
int a,q;
pair<int,int> z[1000005];
vector <int> v;
struct node{
int l,x;
};
node f[4000005];
node combine(node left, node right) {
if (left.l < right.l) return left;
if (left.l == right.l && left.x > right.x) return left;
return right;
}
int bruh=1e16;
int up[100005][25];
int cost[100005][25];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> q;
for (int i=1;i<=a;i++){
cin >> z[i].first >> z[i].second;
v.push_back(z[i].first);
v.push_back(z[i].second);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int n=v.size();
for (int i=1;i<=a;i++){
z[i].first = lower_bound(v.begin(),v.end(),z[i].first)-v.begin()+1;
z[i].second = lower_bound(v.begin(),v.end(),z[i].second)-v.begin()+1;
}
build(1,1,n);
for (int i=1;i<=a;i++){
update(1,1,n,z[i].second,z[i].first,i);
}
while (q--){
int x,y;
cin >> x >> y;
if (x==y){
cout << 0 << "\n";
continue;
}
if (z[x].first>=z[y].second){
cout << "impossible" << "\n";
continue;
}
int p=y;
int ans=0;
for (int i=22;i>=0;i--){
if (z[up[p][i]].first>z[x].second){
ans+= cost[p][i];
p=up[p][i];
}
}
return 0;
}