kth smallest number again
void solve() {
int n, q;
cin >> n >> q;
// v = [{1, 7}, {10, 15}]
vector<pair<int, int>> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i].ff >> arr[i].ss;
}
// v = [{10, 15}, {1, 7}]
sort(arr.begin(), arr.end());
// v = [{1, 7}, {10, 15}];
// case : v = [{1, 7}, {15, 10}];
int idx = 0;
for (int i = 1; i < n; i++) {
if (arr[idx].ff > arr[idx].ss) {
arr[idx].ss = max(arr[idx].ff, arr[idx].ss);
}
else {
idx++;
arr[idx] = arr[i];
}
}
// Searching
while (q--) {
int k;
cin >> k;
int ans = -1;
for (int i = 0; i <= idx; i++) {
if (arr[i].ss - arr[i].ff + 1 > k) {
ans = arr[i].ff + k - 1;
break;
}
else {
k -= arr[i].ss - arr[i].ff + 1;
}
}
cout << ans << '\n';
}
}