#include using namespace std; typedef long long ll; #define F first #define S second #define pii pair #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rep3(i, l, n) for (int i = l; i < n; ++i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define out(a) cout << a << endl #define SZ(v) (int)v.size() #define inf (int)(1e9+7) int main() { int n, k; cin >> n >> k; vector v; int rmax = -inf; rep(i, n) { int a, b; cin >> a >> b; v.eb(a, b); chmax(rmax, b); } int l = 1, r = rmax + 1; int c = 0; while (c++ < 100) { int mid = (l + r) / 2; int cnt = 0; rep(i, n) { if (mid - v[i].F < 0) continue; cnt += min(v[i].S, mid) - v[i].F + 1; if (cnt >= k) break; } out(l << " " << r << " " << mid << " " << cnt); if (cnt >= k) r = mid + 1; //rは開区間 else l = mid; } out((l + r) / 2); }