#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
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);
}
}
set <int> st;
map <int, vector<pair <int, int>>> mp;
for (int i = 1; i <= qq; i ++) {
int x, y;
cin >> x >> y;
st.insert(x); mp[x].push_back({y, i});
}
vector <int> vis(n + 1), dis(n + 1, inf), ans(qq + 1, -1);
queue <int> q;
for (auto s : st) {
q.push(s); vis[s] = 1; dis[s] = 0;
while (!q.empty()) {
int i = q.front(); q.pop();
for (auto x : g[i]) {
dis[x] = min(dis[x], dis[i] + 1);
if (!vis[x]) q.push(x), vis[x] = 1;
}
}
for (auto [y, t] : mp[s]) {
ans[t] = (dis[y] == inf ? -1 : dis[y]);
}
for (int i = 1; i <= n; i ++) dis[i] = inf, vis[i] = 0;
}
for (int i = 1; i <= qq; i ++) {
if (ans[i] == -1) cout << "impossible" << endl;
else cout << ans[i] << endl;
}
return 0;
}