public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));


        class Item implements Comparable<Item>
        {
            private final long profit;
            private final int weight;
            private final int item;

            private Item(int item, long profit, int weight)
            {
                this.item = item;
                this.profit = profit;
                this.weight = weight;
            }

            public int getWeight()
            {
                return weight;
            }

            public long getProfit()
            {
                return profit;
            }


            public int compareTo(Item that)
            {
                if (this.profit < that.profit) {
                    return 1;
                } else if (this.profit > that.profit)
                    return -1;
                else {
                    if (this.weight < that.weight) {
                        return -1;
                    } else if (this.weight > that.weight) {
                        return 1;
                    } else {
                        if (this.item < that.item) {
                            return -1;
                        } else if (this.item > that.item) {
                            return 1;
                        } else
                            return 0;
                    }
                }
            }
        }

        int N = scanner.nextInt();
        int W = scanner.nextInt();

        Item[] array = new Item[N];


        for (int n = 0; n < N; n++) {
            array[n] = new Item(n, scanner.nextInt(), scanner.nextInt());
        }

        Arrays.sort(array);

        MehtaAndTheBankRobbery[][] K = new MehtaAndTheBankRobbery[N + 1][W + 1];

        for (int i = 0; i <= N; i++) {
            for (int w = 0; w <= W; w++) {
                if (i == 0 || w == 0)
                    K[i][w] = new MehtaAndTheBankRobbery(0L, 9);
                else if (array[i - 1].getWeight() <= w) {
                    MehtaAndTheBankRobbery p = K[i - 1][w - array[i - 1].getWeight()];
                    long a;
                    if (p.getIndex() >= 0) {
                        a = array[i - 1].getProfit() * primes[p.getIndex()] + p.getValue();
                    } else {
                        a = array[i - 1].getProfit() + p.getValue();
                    }
                    long b = K[i - 1][w].getValue();
                    if (a > b) {
                        K[i][w] = new MehtaAndTheBankRobbery(a, p.getIndex() - 1);
                    } else {
                        K[i][w] = K[i - 1][w];
                    }
                } else
                    K[i][w] = K[i - 1][w];
            }
        }

        pw.println(K[N][W].getValue());


        scanner.close();
        pw.close();
    }