import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int[][] dp1; static int[][] dp2; static Pizza[] pizzas; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); pizzas = new Pizza[n]; for (int i = 0; i < n; i++) { pizzas[i] = new Pizza(sc.nextInt(), sc.nextInt()); } Arrays.sort(pizzas); dp1 = new int[n][k + 1]; for (int[] arr : dp1) { Arrays.fill(arr, -1); } dp2 = new int[n][k + 1]; for (int[] arr : dp2) { Arrays.fill(arr, -1); } System.out.println(dfw2(n - 1, k)); } static int dfw2(int idx, int v) { if (v < 0) { return Integer.MIN_VALUE; } if (idx < 0) { return 0; } if (dp2[idx][v] < 0) { dp2[idx][v] = Math.max(dfw2(idx - 1, v), dfw1(idx - 1, v - pizzas[idx].price) + pizzas[idx].value); } return dp2[idx][v]; } static int dfw1(int idx, int v) { if (v < 0) { return Integer.MIN_VALUE; } if (idx < 0) { return 0; } if (dp1[idx][v] < 0) { dp1[idx][v] = Math.max(dfw1(idx - 1, v), dfw2(idx - 1, v) + pizzas[idx].value); } return dp1[idx][v]; } static class Pizza implements Comparable { int price; int value; public Pizza(int price, int value) { this.price = price; this.value = value; } public int compareTo(Pizza another) { return price - another.price; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }