#include <bits/stdc++.h>
using namespace std;
struct NODE {
  long long val, x, y;
} dp[100010 * 3];
int cnt[4];
long long pre_sum[4][100010], a[4][100010], ans;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return f * x;
}
inline bool cmp(int x, int y) { return x > y; }
int main() {
  int n = read(), load = read();
  for (int i = 1; i <= n; i++) {
    int w = read(), v = read();
    a[w][++cnt[w]] = v;
  }
  for (int i = 1; i <= 3; i++) {
    sort(a[i] + 1, a[i] + cnt[i] + 1, cmp);
    for (int j = 1; j <= cnt[i]; j++)
      pre_sum[i][j] = pre_sum[i][j - 1] + a[i][j];
  }
  dp[0].val = dp[0].x = dp[0].y = 0;
  for (int i = 1; i <= load; i++) {
    dp[i] = dp[i - 1];
    if (dp[i - 1].val + a[1][dp[i - 1].x + 1] > dp[i].val)
      dp[i].val = dp[i - 1].val + a[1][dp[i - 1].x + 1],
      dp[i].x = dp[i - 1].x + 1, dp[i].y = dp[i - 1].y;
    if (i >= 2 && dp[i - 2].val + a[2][dp[i - 2].y + 1] > dp[i].val)
      dp[i].val = dp[i - 2].val + a[2][dp[i - 2].y + 1], dp[i].x = dp[i - 2].x,
      dp[i].y = dp[i - 2].y + 1;
  }
  ans = 0;
  for (int i = 0; i <= cnt[3]; i++)
    if (load >= i * 3) ans = max(ans, dp[load - i * 3].val + pre_sum[3][i]);
  printf("%lld\n", ans);
  return 0;
}
