#include <bits/stdc++.h>
using namespace std;
vector<int> tval[105];
int dp[105][1005];
int main() {
  int N, T;
  cin >> N >> T;
  int t, q;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> t >> q;
    tval[t - 1].push_back(q);
    if (t == T) ans = max(ans, q);
  }
  for (int i = 0; i < T; i++)
    sort(tval[i].begin(), tval[i].end(), greater<int>());
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++)
    dp[0][i] = dp[0][i - 1] + ((i <= tval[0].size()) ? tval[0][i - 1] : 0);
  int csum;
  for (int i = 1; i < T; i++) {
    for (int j = 0; j <= N; j++) {
      dp[i][j] = (j > 0) ? dp[i][j - 1] : 0;
      csum = 0;
      for (int k = 0; k <= tval[i].size() && k <= j; k++) {
        if (k) csum += tval[i][k - 1];
        dp[i][j] = max(dp[i][j], dp[i - 1][min(N, 2 * (j - k))] + csum);
      }
    }
  }
  if (T > 1)
    cout << max(ans, max(dp[T - 2][0], max(dp[T - 2][1], dp[T - 2][2])))
         << "\n";
  else
    cout << ans << "\n";
}
