import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static long[][][] dp; static Juel[] juels; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); juels = new Juel[n]; for (int i = 0; i < n; i++) { juels[i] = new Juel(sc.nextInt(), sc.nextInt()); } Arrays.sort(juels); dp = new long[2][n][m + 1]; for (long[][] arr1 : dp) { for (long[] arr2 : arr1) { Arrays.fill(arr2, -1); } } System.out.println(dfw(0, n - 1, m)); } static long dfw(int type, int idx, int w) { if (w < 0) { return Integer.MIN_VALUE; } if (idx < 0) { return 0; } if (dp[type][idx][w] < 0) { dp[type][idx][w] = dfw(type, idx - 1, w); if (type == 0) { dp[type][idx][w] = Math.max(dp[type][idx][w], (dfw(1, idx - 1, w - juels[idx].weight) + juels[idx].value) * juels[idx].value); } else { dp[type][idx][w] = Math.max(dp[type][idx][w], (dfw(1, idx - 1, w - juels[idx].weight) + juels[idx].value)); } } return dp[type][idx][w]; } static class Juel implements Comparable { int weight; int value; public Juel(int value, int weight) { this.weight = weight; this.value = value; } public int compareTo(Juel another) { return another.value - value; } } } 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(); } }