#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, T;
  cin >> n >> T;
  priority_queue<pair<int, int> > Q;
  for (int i = 0; i < n; i++) {
    int ti, qi;
    cin >> ti >> qi;
    Q.push(make_pair(T - ti, qi));
  }
  while (Q.size() > 1) {
    pair<int, int> big = Q.top();
    Q.pop();
    pair<int, int> sec = Q.top();
    Q.pop();
    if (big.first == 0) {
      cout << big.second << endl;
      return 0;
    }
    if (big.first != sec.first) {
      big.first--;
      Q.push(big);
      Q.push(sec);
      continue;
    }
    Q.push(make_pair(big.first - 1, big.second + sec.second));
  }
  pair<int, int> only = Q.top();
  cout << only.second << endl;
  return 0;
}
