#include #include using namespace std; const int INF = 1<<28; int n; int a[100], b[100]; int dp[101][100001]; int main(int argc, char *argv[]) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 0; i < 101; i++) fill(dp[i], dp[i] + 100001, INF); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 100001; j++) { if (dp[i][j] == INF) continue; dp[i+1][j+a[i]] = min(dp[i+1][j+a[i]], dp[i][j]); dp[i+1][j] = min(dp[i+1][j], dp[i][j] + b[i]); } } int ret = INF; for (int i = 0; i < 100001; i++) if (dp[n][i] != INF) ret = min(ret, max(i, dp[n][i])); cout << ret << endl; return 0; }