#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long MOD = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N, K; scanf("%lld %lld", &N, &K); vector A(N), B(N); for (ll i = 0; i < N; i++) scanf("%lld %lld", &A[i], &B[i]); ll l = 0; ll r = MOD - 7; while (r - l > 1) { ll mid = (l + r) >> 1; ll cnt = 0; for (ll i = 0; i < N; i++) { if (A[i] <= mid) { ll right = min(mid, B[i]); cnt += right - A[i] + 1; } } if (cnt >= K) r = mid; else l = mid; } cout << r << endl; return 0; }