#include #include using namespace std; const int INF = 1000000000; int main(){ int N, K; cin >> N >> K; vector A(N), B(N); for (int i = 0; i < N; i++){ cin >> A[i] >> B[i]; } int tv = INF; int fv = 0; while (tv - fv > 1){ int mid = (tv + fv) / 2; long long ans = 0; for (int i = 0; i < N; i++){ if (A[i] <= mid){ ans += min(B[i], mid) - A[i] + 1; } } if (ans >= K){ tv = mid; } else { fv = mid; } } cout << tv << endl; }