#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
const int maxn = 12010;
int dp[maxn], n;
int main()
{
int a,b,sum=0,i,j;
cin>>n;
for(int i=1;i<maxn;i++)
dp[i]=200000;
dp[0]=0;
for(i=1;i<=n;i++)
{
cin>>a>>b;
sum+=a+b;
for(j=sum;j>=0;j--)
{
int t=dp[j];
dp[j]=200000;
dp[j+a]=min(dp[j+a],t);
dp[j+b]=min(dp[j+b],t+1);
}
}
sum=sum/2;
for(i=sum;i>=0;i--)
if(dp[i]<=n)
break;
for(j=sum;j<maxn;j++)
if(dp[j]<=n)
break;
cout<<min(dp[i],dp[j])<<endl;
return 0;
}