#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> II;
typedef priority_queue<int> pqD;//降順
typedef priority_queue<int,vector<int>,greater<int>> pqU;//昇順
LL MOD=1000000007;
LL MO2=998244353;
LL INF=1000000000000;
#define SP(x) cout<<setprecision(x)
#define RP(i,n) for(i=0;i<n;i++)
#define RPU(i,n,x) for(i=x;i<n+x;i++)
#define RPD(i,n) for(i=n-1;i<=0;i++)
#define RPDU(i,n,x) for(i=n+x-1;i<=x;i++)
int main(void){
    LL n,i,j,ans=0;
    LL a[4];
    RP(i,4)cin>>a[i];
    sort(a,a+4);
    cout<<a[0]<<endl;
    
}

#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/* alias */
using ull = unsigned long long;
using ll = long long;
/* define short */
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

int main() {

    ll N,K,first,second;
    vector<pair<ll, ll>> AB;
    cin>>N>>K;
    rep(i,N){
        cin>>first>>second;
        AB.push_back({first,second});
    }
    sort(all(AB));
    rep(i,N){
        if(K<AB[i].first){
            break;
        }
        K += AB[i].second;
    }
    cout<<K<<endl;
    return 0;
}