#include <iostream>
using namespace std;
const int N = 1e3+10;
int v[N], w[N], dp[N];
int main(){
int n, V;
cin >> n >> V;
for (int i = 1; i <= n; i ++ ){
cin >> v[i] >> w[i];
}
for (int i = 1; i <= n; i ++ ){
for (int j = V; j >= v[i]; j -- ){
dp[j] = max(dp[j], dp[j-v[i]]+w[i]);
}
}
cout << dp[V];
return 0;
}