#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); constexpr int r = 1'000'000; int n, W; cin >> n >> W; vector dp(r + 1); for(int i = 0; i < n; i++){ int v, w; cin >> v >> w; for(int j = 0; j + w <= r; j++){ dp[j + w] = max(dp[j + w], dp[j] + v); } } ll ans = 0; for(int i = 1; i <= W && i <= r; i++){ int d = W / i; int r = W - d * i; ans = max(ans, (ll)(dp[i]) * d + dp[r]); } cout << ans << '\n'; }