#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int inf = 1e9;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, qq;
cin >> n >> qq;
vector <pair <int, int>> a(n + 1);
for (int i = 1; i <= n; i ++) cin >> a[i].first >> a[i].second;
vector <vector <int>> g(n + 1);
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
if (a[j].first <= a[i].second && a[i].second <= a[j].second) g[i].push_back(j);
}
}
vector <vector <int>> vis(n + 1, vector <int> (n + 1)), dis(n + 1, vector <int> (n + 1, inf));
for (int s = 1; s <= n; s ++) {
queue <int> q;
q.push(s); vis[s][s] = 1; dis[s][s] = 0;
while (!q.empty()) {
int i = q.front(); q.pop();
for (auto x : g[i]) {
dis[s][x] = min(dis[s][x], dis[s][i] + 1);
if (!vis[s][x]) q.push(x), vis[s][x] = 1;
}
}
}
for (int i = 1; i <= qq; i ++) {
int x, y; cin >> x >> y;
if (dis[x][y] == inf) cout << "impossible" << '\n';
else cout << dis[x][y] << '\n';
}
return 0;
}