constint N = 5e5 + 10; int n,m; int dp[N + 100000/*要开大一点,不然越界*/][25];
intmain(){ cin >> n >> m; for (int i = 1;i <= n;i++){ int a,b; cin >> a >> b; dp[a][0] = max(dp[a][0],b); } for (int i = 1;i <= N;i++) dp[i][0] = max(dp[i][0],dp[i - 1][0]); for (int i = 1;i <= 19;i++){ for (int j = 0;j <= N;j++){ dp[j][i] = dp[dp[j][i - 1]][i - 1]; } } while (m--){ int x,y; int res = 0; cin >> x >> y; for (int i = 19;i >= 0;i--){ if (dp[x][i] < y){ res += (1 << i); x = dp[x][i]; } } if (dp[x][0] >= y) cout << res + 1 << endl; elseputs("-1"); } return0; }