#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int main(){ ll N, K; cin >> N >> K; vector> v; rep(i,N){ ll A, B; cin >> A >> B; v.push_back({A,B}); } ll lb = 0, ub = 1000000005; while(ub-lb>1){ ll m = (lb + ub)/2; ll cnt = 0; rep(i,N){ if(v[i][1] <= m) cnt += v[i][1] - v[i][0] + 1; else if(v[i][0] <= m && m < v[i][1]) cnt += m - v[i][0] + 1; } if(cnt<=K) lb = m; else ub = m; } cout << ub << endl; return 0; }