#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>  using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll           long long
#define rep(i,j,n)   for(int i=j;i<n;i++)
#define scn(a)       scanf("%d",&a)
#define scns(a,b)    scanf("%d %d",&a,&b)
#define print(a)     printf("%d\n",a)
#define vec          vector<int>
#define pb           push_back    
#define pairs        pair<int,int>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define mem(a,b)     memset(a,b,sizeof(a))
#define inf          INT_MAX
const int mod = 1e9+7;
const int N = 2e5+5;
 
int n;
 
int main()
{
	int test; test = 1;

    while(test--)
    {
        scn(n);

        int a[n],b[n]; 
        
        vector<pair<ll,pairs>> v1;

        ll sum1 = 0, sum2 = 0;

        rep(i,0,n)
        scns(a[i],b[i]), v1.pb({2LL*a[i]+b[i],{a[i],b[i]}}), sum1 += 1LL*a[i];

        sort(all(v1), greater<pair<ll,pairs>>());

        int cnt = 0;

        rep(i,0,n)
        {
            if(sum1 >= sum2)
            sum2 += 1LL*v1[i].f, cnt++;
            else
            break;
        }

        print(cnt);
    }
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k;
	cin>>n>>k;
  long long int s=k;
  vector<pair<long long int,long long int> > v;
	///s=k;
	//cout<<s;
	//int p=k;
	for(int i=0;i<n;i++)
	{
		long long int a,b;
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	sort(v.begin(),v.end());
	//s=k;
	for(int i=0;i<n;i++)
	{
		if(s<v[i].first)
		break;
		
		s+=v[i].second;
		//k=s;
}
	cout<<s<<endl;
//	for(int i=0;i<v.size();i++)
//	cout<<v[i].first<<" "<<v[i].second;
	return 0;
}