#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<array>
#include<queue>

namespace lib
{
	template<std::uint64_t Mod>struct modnum;
	template<class T>constexpr T pow(T base, std::size_t p)
	{
		if (p == 0)
		{
			return T(1);
		}
		else if (p == 1)
		{
			return base;
		}
		else if (p == 2)
		{
			return base*base;
		}
		else if (p % 2 == 0)
		{
			return pow(pow(base, p / 2), 2);
		}
		else
		{
			return pow(pow(base, p / 2), 2)*base;
		}
	}
	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);

	template<std::uint64_t Mod>struct modnum
	{
		static constexpr auto mod = Mod;
		std::uint64_t val;
		modnum() = default;
		constexpr modnum(std::uint64_t v) :val(v%Mod)
		{

		}

		constexpr modnum& operator+=(modnum const& v)
		{
			val += v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator-=(modnum const& v)
		{
			val += mod - v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator*=(modnum const& v)
		{
			val *= v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator/=(modnum const& v)
		{
			return operator*=(inverse(v));
		}
	};
	template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs += rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, int rhs)
	{
		return lhs += rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator+(int lhs, modnum<Mod> rhs)
	{
		return rhs += lhs;
	}
	template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs -= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs *= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, int rhs)
	{
		return lhs *= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator*(int lhs, modnum<Mod> rhs)
	{
		return rhs *= lhs;
	}

	template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs /= rhs;
	}

	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
	{
		return pow(base, Mod - 2);
	}

	template<class T>constexpr auto clamp(T v)
	{
		return std::max(v, T());
	}
	template<class T>void sort(std::vector<T>& vec)
	{
		std::sort(vec.begin(), vec.end());
	}
	template<class T, class Comp>void sort(std::vector<T>& vec, Comp&& comp)
	{
		std::sort(vec.begin(), vec.end(), std::forward<Comp>(comp));
	}

	template<class T>auto lower_bound(std::vector<T>const& vec, T v)
	{
		return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v));
	}
	template<class T>auto upper_bound(std::vector<T>const& vec, T v)
	{
		return std::distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), v));
	}

	struct scope_exit
	{
		std::function<void(void)> func;
		scope_exit(std::function<void(void)> f) :func(f)
		{

		}
		~scope_exit()
		{
			func();
		}
	};

	template<int val>using int_tag = std::integral_constant<int, val>;
}

void Main();
int main()	
{
	std::cin.tie(nullptr);
	std::cin.sync_with_stdio(false);
	Main();
}

std::uint64_t run(std::array<std::vector<std::uint64_t>, 4>const& data, int index, std::uint64_t rest, std::uint64_t first)
{
	if (index == 4)
	{
		return 0;
	}
	std::uint64_t max{};
	for (int i{}; i < data[index].size() && (first + index)*i <= rest; ++i)
	{
		max = std::max(max, run(data, index + 1, rest - (first + index)*i, first) + data[index][i]);
	}
	return max;
}

void Main()
{
	int N;
	std::uint64_t W;
	std::cin >> N >> W;
	std::uint64_t base_weight;
	std::array<std::vector<std::uint64_t>, 4> data{};
	std::cin >> base_weight;
	data[0].emplace_back(0);
	std::cin >> data[0].back();
	for (int i = 1; i < N; ++i)
	{
		std::uint64_t w, v;
		std::cin >> w >> v;
		data[w - base_weight].emplace_back(v);
	}
	for (auto& vec : data)
	{
		lib::sort(vec, std::greater<>());
		std::uint64_t s{};
		for (auto& v : vec)
		{
			s = s + v;
			v = s;
		}
		vec.emplace(vec.begin(), 0);
	}
	std::cout << run(data, 0, W, base_weight) << std::endl;
}

Measured memory_bytes: 256