#include <bits/stdc++.h>
using namespace std;
int n, T;
vector<int> a[111];
int dp[140][1800];
int main() {
  cin >> n >> T;
  for (int i = 0; i < n; ++i) {
    int q, t;
    cin >> t >> q;
    a[t].push_back(q);
  }
  for (int i = 0; i <= T; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[i][j] = -(int)1e9;
    }
  }
  for (int i = 1; i <= T; ++i) {
    sort(a[i].begin(), a[i].end());
    reverse(a[i].begin(), a[i].end());
    for (int was = 0; was <= n; ++was) {
      int cur = 0;
      dp[i][(was + 1) / 2] = max(dp[i][(was + 1) / 2], dp[i - 1][was]);
      for (int j = 0; j < a[i].size(); ++j) {
        cur += a[i][j];
        dp[i][(was + 1) / 2 + j + 1] =
            max(dp[i - 1][was] + cur, dp[i][(was + 1) / 2 + j + 1]);
      }
    }
  }
  cout << dp[T][1] << '\n';
  return 0;
}
