#include #include #include #include #include #include #include using namespace std; using ll = long long; template int lower_bound(int i0, int i1, F f) { while (i0 < i1) { int i = (i0 + i1) / 2; if (f(i)) i1 = i; else i0 = i + 1; } return i0; } struct P { int a, b; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector

p(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; p[i] = { a, b + 1 }; } //c円以下のものがk枚あるか 満たす中で最も小さいもの int c = lower_bound(1, 1 << 30, [&](int c) { ll s = 0; for (int i = 0; i < n; i++) { if (c < p[i].a) continue; if (c < p[i].b) s += c + 1 - p[i].a; else s += p[i].b - p[i].a; } return s >= (ll)k; }); cout << c << endl; return 0; }