using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp23
{
    class Program
    {

        class item
        {
            /// <summary>
            /// アイテムの重さ
            /// </summary>
            public long weight;
            /// <summary>
            /// アイテムの価値
            /// </summary>
            public int value;
            public item()
            {

                this.weight = 0;
                this.value = 0;
            }
        }
        private static int max(int i, int j)
        {
            if (i < j) return j;
            return i;
        }
        private static long longMin(long i, long j)
        {
            if (i > j) return j;
            return i;
        }
        static void Main(string[] args)
        {
            //入力部
            int N = 0;                        //与えられる荷物の数
            int W = 0;                        //最大容量
            int ans = 0;                      //回答
            long minWaight = 0;
            //int K = 0;
            string[] cin = Console.ReadLine().Split(' ');
            N = int.Parse(cin[0]);
            W = int.Parse(cin[1]);
            List<item> A = new List<item>();
            for (int i = 0; i < N; i++)
            {
                item item = new item();
                cin = Console.ReadLine().Split(' ');

                A.Add(item);
                item.weight = long.Parse(cin[0]);
                item.value = int.Parse(cin[1]);
                if (i == 0)
                {
                    minWaight = item.weight;
                }
                minWaight = longMin(minWaight, item.weight);
            }

            //計算部
            //4種類の重さに分割
            List<item>[] items = new List<item>[4];
            int[][] sumValueSpretted = new int[4][];
            for (int i = 0; i < 4; i++)
            {
                items[i] = A.Where(a => a.weight == minWaight + (long)i).ToList();
                //value降順にソート
                items[i].Sort((a, b) => b.value - a.value);

                //j番目までの価値を計算
                sumValueSpretted[i] = new int[N + 1];
                sumValueSpretted[i][0] = 0;
                for (int j = 0; j < items[i].Count; j++)
                {
                    sumValueSpretted[i][j + 1] = sumValueSpretted[i][j] + items[i][j].value;
                }
            }

            //全探索
            for (int index0 = 0; index0 <= items[0].Count; index0++)
            {
                for (int index1 = 0; index1 <= items[1].Count; index1++)
                {
                    for (int index2 = 0; index2 <= items[2].Count; index2++)
                    {
                        for (int index3 = 0; index3 <= items[3].Count; index3++)
                        {
                            if (index0 * minWaight + index1 * (minWaight + 1) + index2 * (minWaight + 2) + index3 * (minWaight + 3) <= W)
                            {
                                ans = max(ans, sumValueSpretted[0][index0] + sumValueSpretted[1][index1] + sumValueSpretted[2][index2] + sumValueSpretted[3][index3]);
                            }
                        }
                    }
                }
            }

            //出力部
            //cout << ans << "\n";
            Console.WriteLine(ans);
            return;
        }
    }
}


Measured memory_bytes: 13524