#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long a1[maxn], a2[maxn], a3[maxn], n, m, num1, num2, num3, ans, s2[maxn],
    s3[maxn], am[maxn];
bool cmp(long long a, long long b) { return a > b; }
void add1(long long c) {
  num1++;
  a1[num1] = c;
}
void add2(long long c) {
  num2++;
  a2[num2] = c;
}
void add3(long long c) {
  num3++;
  a3[num3] = c;
}
void work() {
  sort(a2 + 1, a2 + num2 + 1, cmp);
  sort(a3 + 1, a3 + num3 + 1, cmp);
  memset(s2, 0, sizeof(s2));
  memset(s3, 0, sizeof(s3));
  for (int i = 1; i <= num2; i++) s2[i] = s2[i - 1] + a2[i];
  for (int i = 1; i <= num3; i++) s3[i] = s3[i - 1] + a3[i];
  for (long long i = 0; i * 2 <= m; i++) {
    long long tp = (m - i * 2) / 3;
    ans = max(ans, s2[min(i, num2)] + s3[min(tp, num3)]);
  }
}
void del2() {
  a2[num2] = 0;
  num2--;
}
int main() {
  cin >> n >> m;
  long long w, c;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &w, &c);
    if (w == 1ll) add1(c);
    if (w == 2ll) add2(c);
    if (w == 3ll) add3(c);
  }
  sort(a1 + 1, a1 + num1 + 1, cmp);
  m--;
  memcpy(am, a2, sizeof(a2));
  long long cnt = 0ll;
  for (int i = 3; i <= num1; i += 2) {
    long long tp = a1[i] + a1[i - 1];
    add2(tp);
    cnt++;
  }
  work();
  m++;
  if (m >= 1) ans += a1[1];
  memcpy(a2, am, sizeof(am));
  for (int i = 2; i <= num1; i += 2) {
    long long tp = a1[i] + a1[i - 1];
    add2(tp);
  }
  work();
  cout << ans << endl;
}
