using System;
using System.Collections.Generic;
using System.Linq;
 
namespace AtCoder
{
    class Program
    {
        static IO io = new IO();
 
        static void Main(string[] args)
        {
            io.ReadSplit();
            int N = io.Int();
            int W = io.Int();
            List<item>[] items = new List<item>[4];
            for (int i = 0; i < 4; ++i)
            {
                items[i] = new List<item>();
            }
            io.ReadSplit();
            item item0 = new item();
            item0.w = io.Int();
            item0.v = io.Int();
            items[0].Add(item0);
            int min_w = item0.w;
            for (int i = 1; i < N; ++i)
            {
                io.ReadSplit();
                item itemX = new item();
                itemX.w = io.Int();
                itemX.v = io.Int();
                items[itemX.w - min_w].Add(itemX);
            }
 
            for (int i = 0; i < 4; ++i)
            {
                items[i] = items[i].OrderByDescending(item => item.v).ToList();
            }
            int total_w = 0;
            int total_v = 0;
            io.WriteLine(Calc(N, W, items, total_w, total_v, 0, 0).ToString());
        }
 
        private static int Calc(int N, int W, List<item>[] items, int total_w, int total_v, int w, int i)
        {
            if (w > 3)
            {
                return total_v;
            }
            if (i >= items[w].Count)
            {
                return Math.Max(total_v, Calc(N, W, items, total_w, total_v, w + 1, 0));
            }
            if (total_w + items[w][i].w <= W)
            {
                int rv = Math.Max(total_v, Calc(N, W, items, total_w + items[w][i].w, total_v + items[w][i].v, w, i + 1));
                return Math.Max(rv, Calc(N, W, items, total_w, total_v, w + 1, 0));
            }
            else
            {
                return total_v;
            }
        }
    }
    public class item
    {
        public int w;
        public int v;
    }
    class IO
    {
        private string[] _Inputs;
        private int _Index;
        public void Read()
        {
            _Inputs = new string[1];
            _Inputs[0] = Console.ReadLine();
            _Index = 0;
        }
        public void ReadSplit()
        {
            _Inputs = Console.ReadLine().Split(' ');
            _Index = 0;
        }
        public string String()
        {
            return _Inputs[_Index++];
        }
        public string[] String(int xCount)
        {
            string[] rv = new string[xCount];
            Array.Copy(_Inputs, _Index, rv, 0, xCount);
            _Index += xCount;
            return rv;
        }
        public int Int()
        {
            return int.Parse(_Inputs[_Index++]);
        }
        public int[] Int(int xCount)
        {
            int[] rv = new int[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = int.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public long Long()
        {
            return long.Parse(_Inputs[_Index++]);
        }
        public long[] Long(int xCount)
        {
            long[] rv = new long[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = long.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public void Write(string xStr)
        {
            Console.Write(xStr);
        }
        public void WriteLine(string xStr)
        {
            Console.WriteLine(xStr);
        }
    }
}

Measured memory_bytes: 13396