#include <bits/stdc++.h>
using namespace std;
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
long long vals[101];
int weights[101];
long long dp[(int)1e5 + 1];
int main() {
  for (int i = 0; i < 101; i++) dp[i] = -1;
  int N, W;
  cin >> N >> W;
  for (int i = 1; i <= N; i++) {
    cin >> weights[i];
    cin >> vals[i];
  }
  dp[0] = 0;
  for (int i = 1; i <= N; i++)
    for (int j = W; j >= 0; j--) {
      if (dp[j] >= 0 && j + weights[i] <= W)
        dp[j + weights[i]] = max(dp[j] + vals[i], dp[j + weights[i]]);
    }
  long long ans = -1;
  for (int i = W; i > 0; i--) ans = max(ans, dp[i]);
  cout << ans;
}
