#include using namespace std; typedef long long ll; int N, K; vector> query; signed main() { cin >> N >> K; query.resize(N); for (int i = 0; i < N; ++i) { cin >> query[i].first >> query[i].second; } int ok = (int)1e9, ng = 0; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; ll cnt = 0; for (auto& q : query) { int a, b; tie(a, b) = q; if (b <= mid) cnt += b - a + 1; else if (a <= mid) cnt += mid - a + 1; } if (cnt >= K) ok = mid; else ng = mid; // cerr << ok << ' ' << ng << endl; } cout << ok << endl; }