#include <bits/stdc++.h>
using namespace std;
long long dp[1010000];
vector<int> vas[300 + 1];
long long sums[1010000 + 1];
int cnts[1010000 + 1];
long long* sum[300 + 1];
bool cmp(int a, int b) { return a > b; }
int s1[1010000];
int s1_cnt = -1;
long long so[1010000];
int nowva;
inline void solve(int l1, int r1, int l2, int r2) {
  if (l1 > r1 || l2 > r2) return;
  int mid = (l1 + r1) >> 1;
  int p = 0;
  for (int i = max(l2, mid - cnts[nowva]); i <= min(r2, mid); ++i) {
    long long va = dp[s1[i]] + sum[nowva][mid - i];
    if (va > so[mid]) so[mid] = va, p = i;
  }
  solve(l1, mid - 1, l2, p);
  solve(mid + 1, r1, p, r2);
}
int n, k, c, v;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &c, &v);
    vas[c].push_back(v);
  }
  for (int i = 1; i <= 300; ++i) sort(vas[i].begin(), vas[i].end(), cmp);
  sum[1] = sums;
  for (int i = 1; i <= 300; ++i) {
    cnts[i] = vas[i].size();
    if (cnts[i]) sum[i][1] = vas[i][0];
    for (int j = 2; j <= cnts[i]; ++j) {
      sum[i][j] = sum[i][j - 1] + vas[i][j - 1];
    }
    sum[i + 1] = sum[i] + cnts[i] + 1;
  }
  for (int i = 1; i <= 300; ++i) {
    nowva = i;
    if (!cnts[i]) continue;
    for (int j = 0; j < i; ++j) {
      s1_cnt = -1;
      for (int l = j; l <= k; l += i) s1[++s1_cnt] = l, so[s1_cnt] = 0;
      if (s1_cnt >= 1) solve(1, s1_cnt, 0, s1_cnt);
      for (int l = 1; l <= s1_cnt; ++l) dp[j + l * i] = so[l];
    }
  }
  printf("%lld\n", dp[k]);
  return 0;
}
