#include <bits/stdc++.h>
using namespace std;
vector<int> star[1005];
int main() {
  int n, t;
  while (scanf("%d%d", &n, &t) != EOF) {
    for (int i = 0; i <= t; i++) star[i].clear();
    for (int i = 0; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      star[a].push_back(b);
    }
    for (int i = 1; i < t; i++) {
      if (star[i].size() % 2) star[i].push_back(0);
      sort(star[i].begin(), star[i].end());
      while (star[i].size()) {
        int a = star[i][star[i].size() - 1];
        star[i].pop_back();
        int b = star[i][star[i].size() - 1];
        star[i].pop_back();
        star[i + 1].push_back(a + b);
      }
    }
    int ans = 0;
    for (int i = 0; i < star[t].size(); i++) ans = max(ans, star[t][i]);
    printf("%d\n", ans);
  }
  return 0;
}
