#include <bits/stdc++.h>
using namespace std;
const int maxn = 100233, modd = 1000000007;
struct zs {
  int t, v;
} a[maxn];
int mp[2][maxn], num[2];
int i, j, k, n, m;
int ra, fh;
char rx;
inline int read() {
  rx = getchar(), ra = 0, fh = 1;
  while (rx < '0' && rx != '-') rx = getchar();
  if (rx == '-') fh = -1, rx = getchar();
  while (rx >= '0') ra = ra * 10 + rx - 48, rx = getchar();
  return ra * fh;
}
bool operator<(zs a, zs b) { return a.t < b.t; }
bool cmp(int a, int b) { return a > b; }
int main() {
  int n = read(), T = read();
  register int i, j;
  for (i = 1; i <= n; i++) a[i].t = read(), a[i].v = read();
  sort(a + 1, a + 1 + n);
  int top = 1;
  bool now = 1, pre = 0;
  for (i = 1; i <= T; i++, now ^= 1, pre ^= 1) {
    while (top <= n && a[top].t == i) mp[pre][++num[pre]] = a[top++].v;
    sort(mp[pre] + 1, mp[pre] + 1 + num[pre], cmp);
    if (i == T) return printf("%d\n", mp[pre][1]), 0;
    if (num[pre] & 1) mp[pre][++num[pre]] = 0;
    for (j = 1, num[now] = 0; j < num[pre]; j += 2)
      mp[now][++num[now]] = mp[pre][j] + mp[pre][j + 1];
  }
}
