#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define int long long int
#define endl '\n'

void solve() {

    int n, k;
    cin >> n >> k;
    vector<pair<int, int>>v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    vector<pair<int, int>>req;
    for (int i = 0; i < n; i++) {
        int sum = 0;
        int zx = v[i].first;
        while (i < n && v[i].first == zx) {
            sum += v[i].second;
            i++;
        }
        i--;
        req.push_back({zx, sum});
    }
    sort(req.begin(), req.end());
    v.clear();
    v = req;
    n = v.size();
    // deb(v)
    int ans = 0;
    if (k >= v[0].first) {
        k -= v[0].first;
        k += v[0].second;
        for (int i = 1; i < n; i++) {
            if (k >= (v[i].first - v[i - 1].first)) {

                k -= (v[i].first - v[i - 1].first);
                k += (v[i].second);
            }
            else {
                cout << v[i - 1].first + k << endl;
                return;
            }
        }
        if (k >= 0) {
            cout << v.back().first + k << endl;
        }
    }
    else {
        cout << k;
    }


}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int  t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(void) {
	int n;
	long long k;
	long long x, y;
	vector<pair<long long, long long> >a;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		a.push_back({ x,y }); //a[i].first=A_i, a[i].second=B_i
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (a[i].first > k)break;
		k += a[i].second;
	}
	cout << k << endl;
	return 0;
}