#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll b,c;
	scanf("%lld%lld",&b,&c);
	ll cnt=0;
	if(b<=0){
		cnt=c+1;
		c--;
		if(b==0)cnt--;
		if(c>0&&b<0)cnt+=min(-2*b-1,c-1);
	}else {
		cnt=c+(c==1?1:0);
		cnt+=min(2*b-1,c-1);
	}printf("%lld\n",cnt);
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll INF = 1e18;

 
int main() {
  
  int n;
  cin >> n;
  vector<ll> a(n);
  ll m = 0;
  rep(i,n){
    ll x, y;
    cin >> x >> y;
    a[i] = 2 * x + y;
    m += x;
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll count = 0;
  rep(i,n){
    count += a[i];
    if(count > m){
      cout << i+1 << endl;
      break;
    }
  }
  
  
  return 0;
}