using System;

namespace ABC060D
{
    class Program
    {
        // After reading editorial
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int N = Int32.Parse(bufs[0]);
            int W = Int32.Parse(bufs[1]);

            int w0, w1, w2, w3;
            int[] v0 = new int[N];
            int[] v1 = new int[N];
            int[] v2 = new int[N];
            int[] v3 = new int[N];

            int n0 = 1;
            int n1 = 0;
            int n2 = 0;
            int n3 = 0;

            bufs = Console.ReadLine().Split(' ');
            w0 = Int32.Parse(bufs[0]);
            w1 = w0 + 1;
            w2 = w0 + 2;
            w3 = w0 + 3;
            v0[0] = Int32.Parse(bufs[1]);

            for (int i = 1; i < N; i++)
            {
                bufs = Console.ReadLine().Split(' ');
                int w = Int32.Parse(bufs[0]);
                int v = Int32.Parse(bufs[1]);

                if (w == w0)
                {
                    DescInsert(ref v0, v, n0++);
                }
                else if (w == w1)
                {
                    DescInsert(ref v1, v, n1++);
                }
                else if (w == w2)
                {
                    DescInsert(ref v2, v, n2++);
                }
                else if (w == w3)
                {
                    DescInsert(ref v3, v, n3++);
                }
            }

            int pick0 = Math.Min(W / w0, n0);
            int pick1, pick2, pick3;

            int res = 0;

            while (pick0 >= 0)
            {
                int remain = W - w0 * pick0;

                pick1 = Math.Min(remain / w1, n1);
                while (pick1 >= 0)
                {
                    remain = W - w0 * pick0 - w1 * pick1;
                    pick2 = Math.Min(remain / w2, n2);
                    while (pick2 >= 0)
                    {
                        remain = W - w0 * pick0 - w1 * pick1 - w2 * pick2;
                        pick3 = Math.Min(remain / w3, n3);

                        int sum = 0;
                        for (int i = 0; i < pick0; i++)
                        {
                            sum += v0[i];
                        }
                        for (int i = 0; i < pick1; i++)
                        {
                            sum += v1[i];
                        }
                        for (int i = 0; i < pick2; i++)
                        {
                            sum += v2[i];
                        }
                        for (int i = 0; i < pick3; i++)
                        {
                            sum += v3[i];
                        }

                        if (res < sum) { res = sum; }

                        pick2--;
                    }

                    pick1--;
                }

                pick0--;
            }

            Console.WriteLine(res);
        }

        static void DescInsert(ref int[] arr, int src, int len)
        {
            for (int i = len - 1; i >= 0; i--)
            {
                if (arr[i] > src)
                {
                    arr[i + 1] = src;
                    return;
                }
                arr[i + 1] = arr[i];
            }

            arr[0] = src;
        }
    }
}


Measured memory_bytes: 11220