#include <bits/stdc++.h>
using namespace std;
const long long L = 200005;
char LZH[L], *S = LZH, *T = LZH;
inline char gc() {
  if (S == T) {
    T = (S = LZH) + fread(LZH, 1, L, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
inline long long read() {
  long long x = 0, f = 1;
  char c = gc();
  for (; c < '0' || c > '9'; c = gc())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = gc()) x = (x << 1) + (x << 3) + c - 48;
  return x * f;
}
priority_queue<int> a[1005];
int n, m;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    a[x].push(y);
  }
  for (int i = 1; i < m; i++) {
    while (!a[i].empty()) {
      int x = a[i].top();
      a[i].pop();
      if (a[i].empty()) {
        a[i + 1].push(x);
        continue;
      }
      int y = a[i].top();
      a[i].pop();
      a[i + 1].push(x + y);
    }
  }
  printf("%d\n", a[m].top());
  return 0;
}
