#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <ctype.h>
#include <vector>
#include <regex>
#include <locale>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <iterator>
#include <set>
#include <climits>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define INF 1e9 + 5
#define MOD 1000000007

using namespace std;

void leftrotate(string &s, int d) {
    reverse(s.begin(), s.begin()+d);
    reverse(s.begin()+d, s.end());
    reverse(s.begin(), s.end());
}

void rightrotate(string &s, int d) {
    leftrotate(s, s.length()-d);
}

std::string ltrim(const std::string& s) {
	return std::regex_replace(s, std::regex("^\\s+"), std::string(""));
}

std::string rtrim(const std::string& s) {
	return std::regex_replace(s, std::regex("\\s+$"), std::string(""));
}

std::string trim(const std::string& s) {
	return ltrim(rtrim(s));
}

void helper (ll A, string& result) {
	if (A > 1)
        helper (A / 2, result);
    result += to_string (A % 2);
}

string dec_to_bin (ll A) {
    string result;
    helper (A, result);
    return result;
}

void print_int_matrix_vector (vector<vector<ll>> &mat) {
    for_each (mat.begin (), mat.end (), [](auto x) {for_each (x.begin (), x.end (), [](ll x){cout << x << ' ';});cout << '\n';});
    cout << '\n';
}

void print_int_vector (vector<int> &vec) {
    for_each (vec.begin (), vec.end (), [](int x){cout << x << ' ';});
    cout << '\n';
}

void replace (string &s, const char search, const char key) {
    replace(s.begin(), s.end(), search, key);
}

void int_vector_to_string (vector<int>& vec, string& ans, int start = 0, int end = 0) {
    for_each (vec.begin () + start, vec.end () - end, [&ans](int x){ans += to_string (x);});
}

string multiply (string a, string b) {
    int a_len = a.size (), b_len = b.size ();
    vector<int> vals((a_len + b_len + 1), 0);
    for (int i = b_len - 1; i >= 0; --i) {
        for (int j = a_len - 1; j >= 0; --j) {
            int num1 = b[i] - '0', num2 = a[j] - '0';
            int mul = num1 * num2;
            if (mul > 9) {
                vals[i + j + 1] += mul % 10;
                vals[i + j ] += mul / 10;
            } else {
                vals[i + j + 1] += mul;
            }
            if (vals[i + j + 1] > 9) {
                mul = vals[i + j + 1];
                vals[i + j + 1] = mul % 10;
                vals[i + j] += mul / 10;
            }
        }
    }
    int i = 0;
    while (vals[i] == 0) {
        i++;
    }
    string ans = "";
    int_vector_to_string (vals, ans, i, 1);
    return ans;
}

int get_first_negative (vector<int>& vt) {
    int low = 0, high = vt.size () - 1;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (vt[mid] < 0 && vt[max (mid - 1, 0)] >= 0) {
            return mid;
        } else if (vt[mid] >= 0) {
            low = mid + 1;
        } else if (vt[max (mid - 1, 0)] < 0) {
            high = mid - 1;
        }
    }
    return -1;
}

int get_first_zero (vector<int>& vt) {
    int low = 0, high = vt.size () - 1;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (vt[mid] == 0 && vt[max (mid - 1, 0)]  == 1) {
            return mid;
        } else if (vt[mid] == 1) {
            low = mid + 1;
        } else if (vt[mid] == 0) {
            high = mid - 1;
        }
    }
    return -1;
}

ll knapsack (vector<pair<ll, ll>> &items, ll w) {
  int n = items.size ();
  vector<vector<ll>> t(n + 1, vector<ll>(w + 1, 0));
  for (ll i = 1; i <= n; ++i) {
    for (ll j = 1; j <= w; ++j) {
      if (items[i - 1].second <= j) {
        t[i][j] = max (items[i - 1].first + t[i - 1][j - items[i - 1].second], t[i - 1][j]);
      } else {
        t[i][j] = t[i - 1][j];
      }
    }
  }
  return t[n][w];
}

int main () {
  FASTIO
  ll n, w;
  cin >> n >> w;
  vector<pair<ll, ll>> items (n);
  for (auto &elem: items) {
    cin >> elem.second >> elem.first;
  }
  cout << knapsack (items, w);
  return 0;
}




Measured memory_bytes: 80256