#include <iostream>
using namespace std;
const int N = 10001;
int n, wt[N], val[N], DP[N][101];
int main() {
while ( cin >> n ) {
for ( int i = 1; i <= n; ++i )
cin >> wt[i] >> val[i];
for ( int w = wt[1]; w <= 100; ++w )
DP[1][w] = val[1];
for ( int i = 2; i <= n; ++i )
for ( int j = 1; j <= 100; ++j ) {
DP[i][j] = DP[i - 1][j];
if ( wt[i] <= j )
DP[i][j] = max ( DP[i][j], DP[i - 1][j - wt[i]] + val[i] );
}
cout << DP[n][100] << endl;
for ( int i = 0; i < n; ++i )
fill ( DP[i], DP[i] + 101, 0 );
}
return 0;
}