#include using namespace std; typedef long long int ll; typedef unsigned long long int llu; typedef pair pii; typedef vector vi; typedef vector > vii; #define rrep(i, m, n) for(int i=m; i=m; i--) #define erev(i, n) for(int i=n; i>=1; i--) #define rev(i, n) for(int i=n-1; i>=0; i--) #define EACH(v) (v).begin(), (v).end() #define CNT(a, n, x) (upper_bound(a, a+n, x)-lower_bound(a, a+n, x)) #define minup(m, x) (m=min(m, x)) #define maxup(m, x) (m=max(m, x)) #define mp make_pair #define INF 1000000000 #define MOD 1000000009 #define EPS 1E-9 #define MAX_N 10000 #define MAX_V 10000 #define MAX_T 10000 int n; bool dp[MAX_V+MAX_T+1]; int main() { cin >> n; vii vt(n); rep(i, n) cin >> vt[i].first >> vt[i].second; sort(EACH(vt)); dp[0] = true; rep(i, n) rev(j, vt[i].second) dp[vt[i].first + j] |= dp[j]; rev(i, MAX_V+MAX_T) if(dp[i]){ cout << i << endl; break; } return 0; }