#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define pers(i, n, s) for (int i = n - 1; i >= s; i--)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define lb(v, n) lower_bound(all(v), n)
#define lbi(v, n) lower_bound(all(v), n) - v.begin()
#define ub(v, n) upper_bound(all(v), n)
#define ubi(v, n) upper_bound(all(v), n) - v.begin()

#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
#include <math.h>

#define outve(v)          \
    for (auto i : v)      \
        cout << i << " "; \
    cout << endl
#define outmat(v)             \
    for (auto i : v)          \
    {                         \
        for (auto j : i)      \
            cout << j << " "; \
        cout << endl;         \
    }
#define in(n, v)                  \
    for (int i = 0; i < (n); i++) \
    {                             \
        cin >> v[i];              \
    }
#define IN(n, m, v) \
    rep(i, n) rep(j, m) { cin >> v[i][j]; }
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
template <typename T>
using pq2 = priority_queue<T>;
template <typename T>
using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

ll N, K;
vector<pair<ll, ll>> info;

void solve()
{

    cin >> N >> K;
    

    for (ll i = 0; i < N; i++)
    {
        ll a, b;
        cin >> a >> b;
        info.push_back(make_pair(a, b));
    }
    sort(info.begin(), info.end());
    for (ll i = 0; i < N; i++)
    {
        if (info[i].first > K)
            break;
        K += info[i].second;
    }
    cout << K << endl;
}
int main()
{

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();

    return 0;
}
/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Do not pray for an easy life, pray for the strength to endure a difficult one.
When something is important enough, you do it even if the odds are not in your favor.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.
No matter how hard it gets, NEVER GIVE UP*/
// set<int>::iterator it;
// set<int>::reverse_iterator it;
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
ll bs(ll a[],ll target,int n){
	int l=0,r=n;
	ll ans=-1;
	while(l<r){
		int mid=(l+r)/2;
		if(a[mid]<target){
			ans=a[mid];
			l=mid+1;
		}
		else if(a[mid]>target){
			r=mid-1;
		}
		else{
			return a[mid];
		}
	}
	return ans;
}
void solve(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	ll b[n];
	// for(int i=0;i<n;i++)
	// 	cin>>a[i]>>b[i];
	pair<ll,ll> p[n];
	for(int i=0;i<n;i++){
		cin>>p[i].first>>p[i].second;
	}
	sort(p,p+n);
	// for(int i=0;i<n;i++){
	// 	mp[a[i]]=b[i];
	// }
	ll ans=0;
	ans=k;
	int index=0;
	while(index<n&&ans>=p[index].first){
		ans+=p[index++].second;
	}
	cout<<ans<<"\n";
	// for(auto m:mp){
	// 	if(ans<m.first){
	// 		break;
	// 	}
	// 	ans+=m.second;
	// }
	// cout<<ans<<"\n";
} 
int main(){
// 	ios::sync_with_stdio(false);
// 	cout.tie(0);
// 	cin.tie(NULL);
	int t;
	// cin>>t;
	t=1;
    while(t--) {
    	// int n;
    	// cin>>n;
    	solve();
	}
}		