#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001;
int n, T;
int q[maxn], t[maxn];
void enter() {
  cin >> n >> T;
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    cin >> t[i] >> q[i];
  }
}
int f[maxn][maxn];
vector<int> g[maxn];
void qhd() {
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    g[T - t[i]].push_back(q[i]);
  }
  for (int i = (0), _b = (T + 1); i < _b; ++i) {
    sort(g[i].begin(), g[i].end());
    g[i].push_back(0);
    reverse(g[i].begin(), g[i].end());
  }
  for (int i = (0), _b = (T + 1); i < _b; ++i) {
    for (int j = 1; j < int(g[i].size()); ++j) {
      g[i][j] += g[i][j - 1];
      f[i][j] = g[i][j];
    }
  }
  for (int i = T; i >= 1; --i) {
    int las;
    if (i > 10)
      las = 1001;
    else
      las = min(1001, (1 << i) + 1);
    int las2 = int(g[i - 1].size());
    int Q;
    if (i - 1 > 10)
      Q = 1000;
    else
      Q = (1 << (i - 1));
    for (int j = 0; j < las; ++j) {
      for (int z = 0; z < las2; ++z)
        if ((j + 1) / 2 + z <= Q)
          f[i - 1][(j + 1) / 2 + z] =
              max(f[i - 1][(j + 1) / 2 + z], f[i][j] + g[i - 1][z]);
    }
  }
  cout << f[0][1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  enter();
  qhd();
}
