#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int last[MAXN];
vector<int> c[MAXN];
int main() {
  int N, T;
  scanf("%d%d", &N, &T);
  for (int i = 0; i < N; i++) {
    int t, q;
    scanf("%d%d", &t, &q);
    c[T - t].push_back(q);
  }
  for (int i = T; i > 0; i--) {
    sort(c[i].begin(), c[i].end());
    for (int j = c[i].size() - 1; j > 0; j -= 2) {
      int cur = c[i][j] + c[i][j - 1];
      c[i - 1].push_back(cur);
    }
    if (c[i].size() % 2 == 1) c[i - 1].push_back(c[i][0]);
  }
  sort(c[0].begin(), c[0].end());
  reverse(c[0].begin(), c[0].end());
  int ans = 0;
  ans = c[0][0];
  printf("%d\n", ans);
  return 0;
}
