#include <bits/stdc++.h>
using namespace std;
vector<int> g[105];
int dp[105][1005];
int s[1005];
int cmp(int a, int b) { return a > b; }
int main() {
  int i, j, n, t, m;
  cin >> n >> t;
  for (i = 1; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a = t - a;
    g[a].push_back(b);
  }
  for (i = 0; i <= t; i++) sort(g[i].begin(), g[i].end(), cmp);
  memset(dp, -1, sizeof(dp));
  dp[0][1] = 0;
  for (i = 0; i <= t; i++) {
    s[0] = 0;
    for (j = 0; j < g[i].size(); j++) {
      s[j + 1] = s[j] + g[i][j];
    }
    for (j = 0; j <= n; j++) {
      if (dp[i][j] == -1) continue;
      int p = g[i].size();
      for (int f = 0; f <= p && f <= j; f++) {
        int w = (j - f) * 2;
        if (w > n) w = n;
        dp[i + 1][w] = max(dp[i + 1][w], dp[i][j] + s[f]);
      }
    }
  }
  int ss = 0;
  for (j = 0; j <= n; j++) ss = max(dp[t + 1][j], ss);
  cout << ss << endl;
}
