import java.util.Scanner;
public class Main {
int maxN = 1002;
int[] vi = new int[maxN];
int[] wi = new int[maxN];
Scanner sc = new Scanner(System.in);
public void start() {
int n = sc.nextInt();
int m = sc.nextInt();
for (int i = 0; i < n; i++) {
vi[i] = sc.nextInt();
wi[i] = sc.nextInt();
}
int res = dp1(n, m);
System.out.println(res);
}
public int dp1(int n, int m) {
int[] dp = new int[m + 1];
for (int i = 0; i < n; i++) {
for (int j = vi[i]; j <= m; j++) {
dp[j] = Math.max(dp[j], dp[j - vi[i]] + wi[i]);
}
}
return dp[m];
}
public int dp2(int n, int m) {
int[] dp = new int[m + 1];
for (int i = 0; i < n; i++) {
for (int j = m; j >= vi[i]; j--) {
for (int k = 0; k * vi[i] <= j; k++) { // 转化为01背包问题,每种可以选取多种
dp[j] = Math.max(dp[j], dp[j - k * vi[i]] + k * wi[i]);
}
}
}
return dp[m];
}
public static void main(String[] args) {
new Main().start();
}
}