#include <bits/stdc++.h>
#define BUFFER_SIZE 1 << 17
#define NMAX 5005
#define GMAX 10005
char BUFFER[BUFFER_SIZE];
int pos = BUFFER_SIZE;
int dp[GMAX];
inline char next() {
if (pos == BUFFER_SIZE) {
fread(BUFFER, 1, BUFFER_SIZE, stdin);
pos = 0;
}
return BUFFER[pos++];
}
inline int read() {
int n = 0;
char c = next();
while (!('0' <= c && c <= '9')) {
c = next();
}
while ('0' <= c && c <= '9') {
n = (n << 3) + (n << 1) + (c - '0');
c = next();
}
return n;
}
int main() {
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
int n = read(), g = read();
int w, p;
for (int i = 1 ; i <= n ; ++i) {
w = read(), p = read();
for (int j = g - w ; j >= 0 ; --j) {
dp[j + w] = std::max(dp[j + w], dp[j] + p);
}
}
printf("%d\n", dp[g]);
return 0;
}