#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, ma1 = 8, ma = 2 * 16 * 1024;
int n, t, dp[102][1001];
vector<int> q[101];
int main() {
  iostream::sync_with_stdio(0);
  cin >> n >> t;
  for (long long i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    q[t - a].push_back(b);
  }
  for (long long i = 0; i < t + 1; i++) {
    sort(q[i].begin(), q[i].end());
    reverse(q[i].begin(), q[i].end());
  }
  for (long long i = 0; i < 102; i++)
    for (long long j = 0; j < 1001; j++) dp[i][j] = -10000000;
  dp[0][0] = dp[0][1] = 0;
  for (int j = 0; j <= t; j++) {
    for (int k = 0; k <= n; k++) {
      int sm = 0;
      for (int p = 0; p <= min(k, (int)q[j].size()); p++) {
        dp[j + 1][min(2 * (k - p), n)] =
            max(dp[j + 1][min(2 * (k - p), n)], dp[j][k] + sm);
        if (p < (int)q[j].size()) sm += q[j][p];
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= t + 1; j++) {
    for (long long p = 0; p < n + 1; p++) ans = max(ans, dp[j][p]);
  }
  cout << ans;
}
