完全背包
#include <iostream>
using namespace std;
int f[1010];
int main(void) {
int n, m;
cin >> n >> m;
while (n--) {
int v, w;
cin >> v >> w;
for (int i = v; i <= m; ++i)
f[i] = max(f[i], f[i - v] + w);
}
cout << f[m];
return 0;
}