#include <bits/stdc++.h>
using namespace std;
priority_queue<int> Q[200006];
int n, m, x, mx, mxx;
inline int read() {
  int x = 0, c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x;
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) x = read(), Q[x].push(read());
  for (int i = 1; i < m; i++) {
    while (!Q[i].empty()) {
      int tmp = Q[i].top();
      Q[i].pop();
      if (!Q[i].empty()) tmp += Q[i].top(), Q[i].pop();
      Q[i + 1].push(tmp);
    }
  }
  printf("%d\n", Q[m].top());
}
