#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    vector<pair<unsigned long, unsigned long>> fr(N);
    for(auto&& [a, b] : fr)cin >> a >> b;
    sort(begin(fr), end(fr));
    unsigned long now{K};
    for(const auto& [a, b] : fr)if(now < a)return 0 & printf("%lu\n", now);
    else now += b;
    cout << now << endl;
    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;
}