#include using namespace std; const int INF = 1 << 30; int main() { int N; cin >> N; vector< int > dp(100001, INF); dp[0] = 0; for(int i = 0; i < N; i++) { int x, y; cin >> x >> y; vector< int > dp2(100001, INF); for(int j = 100000; j >= 0; j--) { if(j - x >= 0) dp2[j] = min(dp2[j], dp[j - x]); dp2[j] = min(dp2[j], dp[j] + y); } dp.swap(dp2); } int ret = INF; for(int i = 0; i < 100001; i++) { ret = min(ret, max(dp[i], i)); } cout << ret << endl; }