#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T>
inline T abs(T x) {
  return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 1010;
struct Input {
  int n, T;
  int t[N], q[N];
  bool read() {
    if (scanf("%d %d", &n, &T) != 2) return 0;
    for (int i = int(0); i < int(n); ++i) {
      scanf("%d %d", &t[i], &q[i]);
    }
    return 1;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  int ans;
  void write() { cout << ans << endl; }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
const int inf = 1000000000;
struct Solution : Data {
  int d[2][N + 1];
  vector<int> a[110];
  void solve() {
    ans = 0;
    for (int i = int(0); i < int(2); ++i)
      for (int j = int(0); j < int(N + 1); ++j) d[i][j] = -inf;
    d[0][1] = 0;
    for (int i = int(0); i < int(n); ++i) {
      a[t[i]].push_back(q[i]);
      umx(ans, q[i]);
    }
    for (int i = int(0); i < int(T); ++i) {
      sort((a[i]).begin(), (a[i]).end());
      reverse((a[i]).begin(), (a[i]).end());
    }
    for (int i = 0; i < T; ++i) {
      int i0 = (i & 1), i1 = i0 ^ 1;
      for (int j = 0; j <= N; ++j) d[i1][j] = -inf;
      for (int j = 0; j <= N; ++j) {
        int sum = 0;
        for (int k = 0; k <= int(a[T - i - 1].size()) && k <= 2 * j; ++k) {
          umx(d[i1][min(N, 2 * j - k)], d[i0][j] + sum);
          umx(ans, d[i0][j] + sum);
          if (k < int(a[T - i - 1].size())) {
            sum += a[T - i - 1][k];
          }
        }
      }
    }
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
