#include <bits/stdc++.h>
using namespace std;
const int H = 19;
const int maxn = 1 << (H + 1);
int n, T;
int q[maxn], t[maxn];
int w[maxn];
int dp[maxn];
bool mrk[maxn];
int solve() {
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    int h = T - t[i];
    if (h <= H)
      w[i] = (1 << (H - h));
    else {
      mrk[i] = true;
      sum += q[i];
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!mrk[i])
      for (int W = (1 << H); W >= w[i]; --W)
        dp[W] = max(dp[W], dp[W - w[i]] + q[i]);
  int ans = dp[1 << H];
  for (int i = 0; i < (1 << H); ++i) ans = max(ans, dp[i] + sum);
  return ans;
}
int main() {
  scanf("%d %d", &n, &T);
  for (int i = 1; i <= n; ++i) scanf("%d %d", &t[i], &q[i]);
  printf("%d\n", solve());
  return 0;
}
