#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100 + 10;
const ll INF = 2e17;
int n;
int weights[maxn], values[maxn];
ll dp[maxn][100005];
ll rec(int at, int weight_capacity) {
    if(at >= n) {
        return 0;
    }
    
    if(dp[at][weight_capacity] != -1) {
        return dp[at][weight_capacity];
    }
    
    ll res = -INF;
    
    res = max(res, rec(at + 1, weight_capacity));
    
    if(weight_capacity >= weights[at]) {
        res = max(res, rec(at + 1, weight_capacity - weights[at]) + values[at]);
    }
        
    dp[at][weight_capacity] = res;
    return res;
}
int main() {
    
    memset(dp, -1, sizeof dp);
    int W;
    cin >> n >> W;
    
    for(int i = 0; i < n; i++) {
        cin >>  weights[i] >> values[i];
    }
    
    cout << rec(0, W) << endl;
    return 0;
}
