#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF_INT = 2147483647;
const long long INF_LL = 9223372036854775807;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const list<T> &lst) {
  os << "{";
  for (auto itr = lst.begin(); itr != lst.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != lst.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) {
    cerr << ", ";
  }
  dump_func(std::move(tail)...);
}
int N, W;
long long v[201], w[201];
int main(int argc, char *argv[]) {
  cin >> N >> W;
  for (int i = (0); i < (N); ++i) cin >> v[i] >> w[i];
  map<long long, long long> m;
  m[0] = 0;
  for (int i = (0); i < (N); ++i) {
    map<long long, long long> mCopy = m;
    for (auto itr = mCopy.begin(); itr != mCopy.end(); itr++) {
      pair<long long, long long> p = *itr;
      if (p.first + w[i] <= W) {
        m[p.first + w[i]] = max(m[p.first + w[i]], p.second + v[i]);
      }
    }
    m[w[i]] = max(m[w[i]], v[i]);
    ;
  }
  int key = W;
  while (!m[key]) key--;
  cout << m[key] << endl;
  return 0;
}
