#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, T;
long long dp[N][N];
vector<int> v[N];
long long f(int lvl, int num) {
  if (num > n) num = n;
  if (lvl > T) {
    dp[lvl][num] = 0;
    return 0;
  }
  if (dp[lvl][num] != -1) {
    return dp[lvl][num];
  }
  if (num == 0) {
    dp[lvl][num] = 0;
    return 0;
  }
  int sz = v[lvl].size();
  int av = min(num, sz);
  long long ans = 0;
  long long cur = 0;
  for (int i = 0; i <= av; i++) {
    ans = max(ans, cur + f(lvl + 1, (num - i) * 2));
    if (i < av) cur += v[lvl][i];
  }
  dp[lvl][num] = ans;
  return dp[lvl][num];
}
int main() {
  if (fopen("G.in", "r")) freopen("G.in", "r", stdin);
  cin >> n >> T;
  for (int t, q, i = 0; i < n; i++) {
    cin >> t >> q;
    t = T - t;
    v[t].push_back(q);
  }
  for (int i = 0; i <= T; i++) {
    if (v[i].size() != 0) sort(v[i].begin(), v[i].end(), greater<int>());
  }
  memset(dp, -1, sizeof(dp));
  cout << f(0, 1);
  return 0;
}
