#include #include #include using namespace std; int main(){ long long n,k;cin>>n>>k; map A; for(int i = 0; n > i; i++){ int a,b;cin>>a>>b; A[a]++; A[b+1]--; } int prev = -1; long long nw = 0; long long pres = 0; for(auto x: A){ if((x.first-prev)*nw + pres >= k){ cout << prev+(k-pres-1)/nw << endl; return 0; } pres += (x.first-prev)*nw; nw += x.second; prev = x.first; } }