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

#define ll long long
#define MOD 1000000007
#define pii pair <ll, ll>


long long GCD(long long a, long long b)
{
    if (!b) return a;
    return GCD(b, a % b);
}

vector <int> graph[2001];
queue <int> q;
int n;
pii arr[200001];

int main()
{
    ll n, k;
    scanf("%lld %lld", &n, &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld %lld", &arr[i].first, &arr[i].second);
    }
    sort(arr, arr + n);
    for (int i = 0; i < n; i++)
        if (k >= arr[i].first)
            k += arr[i].second;
    printf("%lld", k);
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef pair<int,char> pic;
typedef vector<pii> vpii;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repv(c, it) \
for(auto it = (c).begin(); it != (c).end(); it++)
#define repm(c, it) \
for(mll::iterator it = (c).begin(); it != (c).end(); it++)
#define inf 1000000007
#define pb push_back
const long long mod = 1000000007;
const double pi = acos(-1);








int main() {
    //decreases the time taken by cin,cout.
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("error.txt", "w", stderr);
    freopen("output.txt", "w", stdout);
    #endif
    
    
    ll n,k;cin>>n>>k;
    //ll c[n+1];c[0]=k;
    ll x,y;
    vector<vll> tt(n);
    rep(i,0,n)
    {
    	cin>>x>>y;
    	tt[i].push_back(x);
    	tt[i].push_back(y);
    	
    }
    sort(all(tt));
    //rep(i,0,n){c[i+1]=c[i]+a[i][1];}

    ll ans=k,sum=k;
    rep(i,0,n)
    {
    	if(sum<tt[i][0]){ans=sum;break;}
    	else
    	{
    		sum+=tt[i][1];
    		ans=sum;
    	}
    }
    cout<<ans;

    
    
    return 0;

}



















