using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = ReadNextLong();
            var w = ReadNextLong();
            var weights = new long[4];
            var vs = new List<long>[4];
            for (int i = 0; i < vs.Length; i++)
            {
                vs[i] = new List<long>();
            }
            for (var i = 0; i < n; i++)
            {
                var wi = ReadNextLong();
                var vi = ReadNextLong();

                if (!weights.Contains(wi))
                {
                    weights[Array.IndexOf(weights, 0)] = wi;
                }
                vs[Array.IndexOf(weights, wi)].Add(vi);
            }

            for (int i = 0; i < vs.Length; i++)
            {
                vs[i] = vs[i].OrderByDescending(x => x).ToList();
            }

            long sum = 0;
            for (int i = 0; weights[0] != 0 && i <= Math.Min(vs[0].Count, w / weights[0]); i++)
            {
                ChangeMax(ref sum, vs[0].Take(i).Sum());
                for (int j = 0; weights[1] != 0 && j <= Math.Min(vs[1].Count, w / weights[1]); j++)
                {
                    if (i * weights[0] + j * weights[1] > w) break;
                    ChangeMax(ref sum, vs[0].Take(i).Sum()+ vs[1].Take(j).Sum());
                    for (int k = 0; weights[2] != 0 && k <= Math.Min(vs[2].Count, w / weights[2]); k++)
                    {
                        if (i * weights[0] + j * weights[1] + k * weights[2] > w) break;
                        ChangeMax(ref sum, vs[0].Take(i).Sum() + vs[1].Take(j).Sum() + vs[2].Take(k).Sum());
                        for (int l = 0; weights[3] != 0 && l <= Math.Min(vs[3].Count, w / weights[3]); l++)
                        {
                            if (i * weights[0] + j * weights[1] + k * weights[2] + l * weights[3] > w) break;
                            ChangeMax(ref sum, vs[0].Take(i).Sum() + vs[1].Take(j).Sum() + vs[2].Take(k).Sum() + vs[3].Take(l).Sum());
                        }
                    }
                }
            }

            Console.WriteLine($"{sum}");
        }

        public static bool ChangeMax(ref long lhs, long rhs)
        {
            if (lhs < rhs)
            {
                lhs = rhs;
                return true;
            }
            else
            {
                return false;
            }
        }

        public static T[] CreateArray<T>(int length, T value)
        {
            return Enumerable.Repeat(value, length).ToArray();
        }

        public static T[][] CreateArray2<T>(int length1, int length2, T value)
        {
            return Enumerable.Range(0, length1).Select(_ => CreateArray(length2, value)).ToArray();
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);

        public static string[] Buffer = new string[] { };
        public static int Index;
        public static string ReadStringNext()
        {
            if (Buffer.Length == 0 || Buffer.Length <= Index)
            {
                Buffer = ReadStringArray();
                Index = 0;
            }
            return Buffer[Index++];
        }
        public static int ReadNextInt() => int.Parse(ReadStringNext());
        public static long ReadNextLong() => long.Parse(ReadStringNext());
    }
}


Measured memory_bytes: 17504