#include <bits/stdc++.h>
using namespace std;
int v[10001], viz[10001], c[10001], out[10001], b[10001];
multiset<int, greater<double> > s[10001];
int main() {
  std::ios::sync_with_stdio(false);
  int i, k, n, t, x, y, nr, j;
  long long sol;
  cin >> n >> t;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    if (t >= x) s[t - x].insert(y);
  }
  sol = 0;
  k = 0;
  for (i = t; i >= 0; i--) {
    for (j = 1; j <= k; j++) s[i].insert(v[j]);
    nr = s[i].size();
    if (i <= 20) nr = min(nr, (1 << i));
    if (nr % 2 == 0)
      nr = nr / 2;
    else
      nr = (nr - 1) / 2;
    for (j = 1; j <= nr; j++) {
      v[j] = *(s[i].begin());
      s[i].erase(s[i].begin());
      v[j] = v[j] + *(s[i].begin());
      s[i].erase(s[i].begin());
    }
    k = nr;
    if (i == 0) continue;
    while (s[i].empty() == 0) {
      s[i - 1].insert(*s[i].begin());
      s[i].erase(s[i].begin());
    }
  }
  for (i = 1; i <= k; i++) sol = sol + v[i];
  while (s[0].empty() == 0) {
    if (*s[0].begin() > sol) sol = *s[0].begin();
    s[0].erase(s[0].begin());
  }
  cout << sol;
  return 0;
}
