#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T& x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T& x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 1e3 + 17, maxt = 117;
int n, t;
vector<int> ass[maxn];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> t;
  for (int i = 0, ti, q; i < n; i++) {
    cin >> ti >> q;
    if (ti > t) continue;
    ass[t - ti].push_back(q);
  }
  for (int i = maxt - 1; i; i--) {
    sort(ass[i].begin(), ass[i].end());
    while (ass[i].size() > 1) {
      ass[i - 1].push_back(ass[i].back() + ass[i][ass[i].size() - 2]);
      ass[i].pop_back(), ass[i].pop_back();
      ;
    }
    if (ass[i].size()) ass[i - 1].push_back(ass[i].back());
  }
  sort(ass[0].begin(), ass[0].end());
  cout << ass[0].back() << '\n';
  return 0;
}
