#include using namespace std; int dp[101][100001]; int main(){ int n;cin>>n; for(int i = 0; 100 > i; i++){ for(int j = 0; 100000 >= j; j++){ dp[i][j] = 100001; } } dp[0][0] = 0; for(int i = 0; n > i; i++){ int a,b;cin>>a>>b; for(int j = 0; 100000 > j; j++){ if(!dp[i][j] && i+j != 0)continue; dp[i+1][j+a] = min(dp[i+1][j+a],dp[i][j]); dp[i+1][j] = min(dp[i+1][j],dp[i][j]+b); } } int ans = 100000; for(int i = 0; 100000 >= i; i++){ ans = min(ans,max(i,dp[n][i])); } cout << ans << endl; }