#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
vector<int> v[MAX];
int dp[105][MAX];
int main() {
  ios::sync_with_stdio(false);
  int n, t;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    int t, p;
    cin >> t >> p;
    v[t].push_back(p);
  }
  for (int i = 0; i < MAX; i++) {
    sort(v[i].begin(), v[i].end());
    v[i].push_back(0);
    reverse(v[i].begin(), v[i].end());
    for (int j = 1; j < v[i].size(); j++) v[i][j] += v[i][j - 1];
  }
  for (int i = 1; i <= t; i++)
    for (int j = 1; j < MAX; j++)
      for (int k = 0; k < min((int)v[i].size(), j + 1); k++)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][min(MAX - 1, (j - k) * 2)] + v[i][k]);
  cout << dp[t][1] << endl;
  return 0;
}
