#include <bits/stdc++.h>
using namespace std;
int n, t;
vector<pair<int, int>> v;
int main() {
  scanf("%d%d", &n, &t);
  v.resize(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &v[i].first, &v[i].second);
    v[i].first = t - v[i].first;
    if (v[i].first >= 0) ans = max(v[i].second, ans);
  }
  sort(v.begin(), v.end());
  vector<int> curV, nextV;
  int curT = v.back().first;
  int curInd = v.size() - 1;
  while (curT >= 0) {
    curV = nextV;
    nextV.clear();
    while (curInd >= 0 && v[curInd].first == curT) {
      curV.push_back(v[curInd--].second);
    }
    sort(curV.rbegin(), curV.rend());
    for (int i = 0; i < curV.size(); i += 2) {
      if (i < curV.size() - 1)
        nextV.push_back(curV[i] + curV[i + 1]);
      else
        nextV.push_back(curV[i]);
    }
    curT--;
  }
  sort(curV.begin(), curV.end());
  cout << curV.back();
  return 0;
}
