// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

//type

typedef long long ll;

#define pii pair<int, int>

#define vi vector<int>

//x * y * 1.0 can cause overflow

//constant

#define inf (int)(1e9+7)

#define mod (ll)(1e9+7)

#define eps 1e-10

//omission

#define eb emplace_back

#define F first

#define S second

#define SZ(x) ((int)(x).size())

#define all(v) v.begin(), v.end()

#define ios cin.tie(0); ios::sync_with_stdio(false)

#define FIX(a) cout << fixed << setprecision(a)

//loop

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

#define rep3(i, st, n) for (int i = st; i < n; ++i)

//manip

#define chmax(a, b) a = max(a, b)

#define chmin(a, b) a = min(a, b)

#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());

#define fill(x, y) memset(x, y, sizeof(x))

#define ceil(a, b) a / b + !!(a % b)

template<class T> T power_mod(T a, T b) {return b ? power_mod(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}

template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}

#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())

#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())

template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}

template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!

#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl

#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl

#define out(a) cout << a << endl

#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl



//algorithm

//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0

//bfs, not x, y, i, j

//not !(i % 2), i % 2 == 0

//minimal required terms

//cast caution

//look constraints always

//product of minimum 9 prime numbers is above 1e9





int main() {

    

    

    

    

    int N, W; cin >> N >> W;

    ll dp[100007] = {0};

    

    rep(i, N) {

        int w, v; cin >> w >> v;

        for (int j = W; j >= w; --j) {

            chmax(dp[j], dp[j - w] + v);

        }

    }

    

    out(dp[W]);

    

    

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first

#define S second

#define pii pair<int, int>

#define eb emplace_back

#define all(v) v.begin(), v.end()

#define rep(i, n) for (int i = 0; i < (n); ++i)

#define rep3(i, l, n) for (int i = l; i < (n); ++i)

#define sz(v) (int)v.size()

const int inf = 1e9 + 7;

const ll INF = 1e18;

#define abs(x) (x >= 0 ? x : -(x))

#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())

#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())

template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }

template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }

const int mod = 1000000007;

ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }

template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }







void solve();



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    int T;

    // cin >> T;

    T = 1;



    while (T--) {

        solve();

    }

}



void solve() {

  int n, W;

  cin >> n >> W;

  vector<ll> dp(W + 1);

  rep(i, n) {

    int w, v;

    cin >> w >> v;

    for (int j = W - w; j >= 0; --j) {

      chmax(dp[w + j], dp[j] + v);

    }

  }

  cout << *max_element(all(dp)) << endl;

}


// Fastest known solution for this problem: