#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int MXN = (int)2e2 + 7;
const int mod = (int)1e9 + 9;
vector<int> st[101];
int dp[101][1001];
int main() {
  int n, t;
  scanf("%d %d", &n, &t);
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    st[t - a].push_back(b);
  }
  for (int i = 0; i < t; i++) {
    sort(begin(st[i]), end(st[i]), greater<int>());
    for (int j = 1; j < ((int)(st[i]).size()); j++) st[i][j] += st[i][j - 1];
  }
  for (int i = 0; i < t; i++)
    for (int j = 0; j <= 1000; j++) dp[i][j] = -INF;
  dp[0][1] = 0;
  if (!st[0].empty()) dp[0][0] = st[0][0];
  for (int i = 1; i < t; i++) {
    for (int j = 0; j <= 1000; j++) {
      int jj = min(1000, j * 2);
      dp[i][jj] = max(dp[i][jj], dp[i - 1][j]);
      for (int k = 0; k < ((int)(st[i]).size()); k++) {
        jj = min(1000, j * 2 - k - 1);
        if (jj < 0) break;
        dp[i][jj] = max(dp[i][jj], dp[i - 1][j] + st[i][k]);
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= 1000; j++) ans = max(ans, dp[t - 1][j]);
  printf("%d\n", ans);
  return 0;
}
