#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
  return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int inf = 1e9 + 143;
const long long longinf = 1e18 + 143;
inline int read() {
  int x;
  scanf(" %d", &x);
  return x;
}
const int N = 1010;
const int T = 110;
int f[T][N];
vector<int> v[T];
int main() {
  int n = read();
  int tend = read();
  for (int i = 0; i < n; i++) {
    int t = read();
    int q = read();
    t = tend - t;
    v[t].push_back(q);
  }
  for (int i = 0; i < T; i++) {
    sort((v[i]).begin(), (v[i]).end());
    reverse((v[i]).begin(), (v[i]).end());
  }
  memset(f, -1, sizeof - 1);
  f[T - 1][0] = 0;
  for (int i = T - 1; i > 0; i--) {
    for (int k = 0; k <= n; k++) {
      int ft = f[i][k];
      if (ft == -1) continue;
      int sz = v[i - 1].size();
      int sum = 0;
      for (int c = 0; c <= sz; c++) {
        umax(f[i - 1][(k + 1) / 2 + c], ft + sum);
        if (c < sz) sum += v[i - 1][c];
      }
    }
  }
  printf("%d\n", f[0][1]);
  return 0;
}
