#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int array_size = 1001;
int f[array_size], v[array_size], w[array_size], N, V;
int main() {
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)
f[j] = max(f[j], f[j - v[i]] + w[i]);
cout << f[V];
}