#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-9;
const int maxV = 3e5 + 5;
int n, V, mV, a[maxV], tot;
long long dp[5][maxV];
vector<long long> w[5];
void solve(int l, int r, int L, int R, int id) {
  if (l > r) return;
  int pos = L, mid = l + r >> 1;
  for (int i = max(mid - (int)w[id].size(), L); i <= min(mid, R); i++) {
    if (dp[id][a[mid]] <
        dp[id - 1][a[i]] + (i == mid ? 0 : w[id][mid - i - 1])) {
      dp[id][a[mid]] = dp[id - 1][a[i]] + (i == mid ? 0 : w[id][mid - i - 1]);
      pos = i;
    }
  }
  solve(l, mid - 1, L, pos, id);
  solve(mid + 1, r, pos, R, id);
}
namespace fastIO {
static char buf[100000], *h = buf, *d = buf;
template <typename T>
inline void read(T& x) {
  int f = 1;
  x = 0;
  register char c(
      h == d && (d = (h = buf) + fread(buf, 1, 100000, stdin), h == d) ? EOF
                                                                       : *h++);
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = h == d && (d = (h = buf) + fread(buf, 1, 100000, stdin), h == d) ? EOF
                                                                         : *h++;
  }
  while (c <= '9' && c >= '0')
    x = (x << 1) + (x << 3) + (c ^ 48),
    c = h == d && (d = (h = buf) + fread(buf, 1, 100000, stdin), h == d) ? EOF
                                                                         : *h++;
  x *= f;
}
template <typename T>
void output(T x) {
  if (x < 0) {
    putchar('-');
    x = ~(x - 1);
  }
  static int s[20], top = 0;
  while (x) {
    s[++top] = x % 10;
    x /= 10;
  }
  if (!top) s[++top] = 0;
  while (top) putchar(s[top--] + '0');
}
}  // namespace fastIO
using fastIO::output;
using fastIO::read;
int main() {
  read(n), read(V);
  for (int i = (1); i <= (int)(n); ++i) {
    int c, w0;
    read(c), read(w0);
    w[c].push_back(w0);
    mV = max(mV, c);
  }
  for (int i = (1); i <= (int)(mV); ++i) {
    sort(w[i].begin(), w[i].end(), greater<int>());
    for (int j = 1; j < w[i].size(); j++) {
      w[i][j] += w[i][j - 1];
    }
  }
  for (int i = (1); i <= (int)(mV); ++i) {
    for (int j = (0); j <= (int)(i - 1); ++j) {
      tot = 0;
      for (int k = j; k <= V; k += i) {
        a[++tot] = k;
      }
      solve(1, tot, 1, tot, i);
    }
  }
  int flag = 0;
  printf("%lld\n", dp[mV][V]);
  return 0;
}
