#include <bits/stdc++.h>
using namespace std;
int n, T;
vector<vector<int> > lvl;
int dp[110][2000];
int calc(int level, int free) {
  if (level >= T) {
    return 0;
  }
  if (free >= 1000) {
    int ans = 0;
    for (int i = level; i < lvl.size(); i++) {
      for (int j = 0; j < lvl[i].size(); j++) ans += lvl[i][j];
    }
    return ans;
  }
  if (dp[level][free] != -1) return dp[level][free];
  int answer = 0;
  int sz = (int)lvl[level].size();
  for (int i = 0; i <= min(free, sz); i++) {
    int cur = 0;
    for (int j = 0; j < i; j++) cur += lvl[level][j];
    answer = max(answer, cur + calc(level + 1, 2 * (free - i)));
  }
  dp[level][free] = answer;
  return answer;
}
bool cmp(int a, int b) { return a > b; }
int main(int argc, const char* argv[]) {
  cin >> n >> T;
  lvl.resize(T);
  for (int i = 0; i < 110; i++)
    for (int j = 0; j < 2000; j++) dp[i][j] = -1;
  for (int i = 0; i < n; i++) {
    int t, q;
    cin >> t >> q;
    if (T - t >= 0) lvl[T - t].push_back(q);
  }
  for (int i = 0; i < T; i++) {
    sort(lvl[i].begin(), lvl[i].end(), &cmp);
  }
  cout << calc(0, 1) << endl;
}
