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

namespace AtCoderBeginnerContest
{
    public class Program
    {
        static long N;

        public static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            N = line1[0];
            long W = line1[1];

            long[] w = new long[N];
            long[] v = new long[N];

            long w1 = 0;
            var wvList1 = new List<long>();
            var wvList2 = new List<long>();
            var wvList3 = new List<long>();
            var wvList4 = new List<long>();
            for (int i = 0; i < N; i++)
            {
                long[] t = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                if (i == 0) w1 = t[0];
                if (t[0] == w1) wvList1.Add(t[1]);
                if (t[0] == w1+1) wvList2.Add(t[1]);
                if (t[0] == w1+2) wvList3.Add(t[1]);
                if (t[0] == w1+3) wvList4.Add(t[1]);
            }
            wvList1.Add(0);
            wvList2.Add(0);
            wvList3.Add(0);
            wvList4.Add(0);
            wvList1.Sort();
            wvList1.Reverse();
            wvList2.Sort();
            wvList2.Reverse();
            wvList3.Sort();
            wvList3.Reverse();
            wvList4.Sort();
            wvList4.Reverse();
            long max = 0;
            long maxw1 = 0;
            long maxw2 = 0;
            long maxw3 = 0;
            long maxw4 = 0;
            long wc1 = 0;
            long wc2 = 0;
            long wc3 = 0;
            long wc4 = 0;

            for (int i = 0; i < wvList1.Count; i++)
            {
                if(wvList1[i]!=0)
                {
                    for (int a = 0; a < i + 1; a++)
                    {
                        maxw1 += wvList1[a];
                        wc1++;
                    }
                    if (wc1 * w1 > W)
                    {
                        maxw1 = 0;
                        wc1 = 0;
                        continue;
                    }
                }
                for (int j = 0; j < wvList2.Count; j++)
                {
                    if (wvList2[j] != 0)
                    {
                        for (int a = 0; a < j + 1; a++)
                        {
                            maxw2 += wvList2[a];
                            wc2++;
                        }
                        if (wc1 * w1 + wc2 * (w1 + 1) > W)
                        {
                            maxw2 = 0;
                            wc2 = 0;
                            continue;
                        }
                    }
                    for (int m = 0; m < wvList3.Count; m++)
                    {
                        if(wvList3[m]!=0)
                        {
                            for (int a = 0; a < m + 1; a++)
                            {
                                maxw3 += wvList3[a];
                                wc3++;
                            }
                            if (wc1 * w1 + wc2 * (w1 + 1) + wc3 * (w1 + 2) > W)
                            {
                                maxw3 = 0;
                                wc3 = 0;
                                continue;
                            }
                        }
                        for (int n = 0; n < wvList4.Count; n++)
                        {
                            if(wvList4[n]!=0)
                            {
                                for (int a = 0; a < n + 1; a++)
                                {
                                    maxw4 += wvList4[a];
                                    wc4++;
                                }
                                if (wc1 * w1 + wc2 * (w1 + 1) + wc3 * (w1 + 2) + wc4 * (w1 + 3) > W)
                                {
                                    maxw4 = 0;
                                    wc4 = 0;
                                    continue;
                                }
                            }
                            max = Math.Max(max, maxw1 + maxw2 + maxw3 + maxw4);
                            maxw4 = 0;
                            wc4 = 0;
                        }
                        maxw3 = 0;
                        wc3 = 0;
                    }
                    maxw2 = 0;
                    wc2 = 0;
                }
                maxw1 = 0;
                wc1 = 0;
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 13780