#include <bits/stdc++.h>
using namespace std;
int n, T;
vector<int> quest[1002];
int dp[1002][1002];
int f(int place, int now) {
  if (now == T) return 0;
  if (dp[place][now] != -1) return dp[place][now];
  int &ret = dp[place][now] = f(min(place << 1, n), now + 1);
  int sum = 0;
  int mini = min(place, (int)quest[now].size());
  for (int i = 0; i < mini; i++) {
    sum += quest[now][i];
    ret = max(ret, sum + f(min(place - i - 1 << 1, n), now + 1));
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &T);
  int t, q;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &t, &q);
    quest[T - t].push_back(q);
  }
  for (int i = 0; i < T; i++)
    sort(quest[i].begin(), quest[i].end(), greater<int>());
  memset(dp, -1, sizeof dp);
  printf("%d\n", f(1, 0));
  return 0;
}
