#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,k;
  cin >> n >> k;
  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a.begin(),a.end());
  
  ll x=0,ans;
  rep(i,n){
    if(k<a[i].first-x){
      ans=x+k; break;
    }
    k-=a[i].first-x;
    k+=a[i].second;
    x=a[i].first;
    ans=a[i].first+k;
  }
  
  cout << ans << endl;
  
}
#include "bits/stdc++.h"
using namespace std;

#define ll long long int 
#define pb(a) push_back(a)
#define vll vector<ll>
#define loop(i, n) for(ll i=1;i<=n;i++)
#define loop0(i, n) for(ll i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define mp(i, j) make_pair(i, j)
#define google cout<<"Case #"<<tc-t<<": ";
const ll mod = 1000000007;
const ll big = 2999999999999999999;
const ll small = -2999999999999999999;
void in2(ll& a, ll& b) { in(a); in(b); }
void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); }
void swap(ll& a, ll& b) { a = a+b; b = a-b; a = a-b; }
void arrayIn(vll& a, ll& n) { loop0(i, n) in(a[i]); }

ll n, dp[101][100001];
vll t;

ll solve(ll i, ll rem)
{
  if(rem < 0)
    return small;
  if(i == n)
    return 0;
  if(dp[i][rem] != -1)
    return dp[i][rem];
  return dp[i][rem] = max(solve(i+1, rem-t[i])+t[i], solve(i+1, rem));
}

void solve()
{
  memset(dp, -1, sizeof(dp));
  in(n);
  t.resize(n);
  ll tot = 0;
  loop0(i, n)
  {
    in(t[i]);
    tot += t[i];
  }
  sort(t.begin(), t.end(), greater<ll>());
  ll rem = (tot+1)/2;
  ll ans = solve(0, rem);
  cout<<max(ans, tot-ans)<<"\n";
}

int main()
{
    solve();
}

