#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = false;
const int MOD = 1000000007;
const int MX = 1010;
int dp[MX][MX];
int T, N;
vector<int> tasks[MX];
int f(int t, int slots) {
  if (t < 0) return 0;
  slots = min(slots, N);
  int& ans = dp[t][slots];
  if (ans >= 0) return ans;
  ans = 0;
  int gain = 0;
  for (int i = (0); i < int(slots + 1); i++) {
    ans = max(ans, gain + f(t - 1, (slots - i) * 2));
    if (i < tasks[t].size()) gain += tasks[t][i];
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &(N));
  scanf("%d", &(T));
  for (int i = (0); i < int(N); i++) {
    int t;
    scanf("%d", &(t));
    ;
    int q;
    scanf("%d", &(q));
    ;
    tasks[t].push_back(q);
  }
  for (int i = (0); i < int(MX); i++) {
    sort(tasks[i].begin(), tasks[i].end());
    reverse(tasks[i].begin(), tasks[i].end());
  }
  printf("%d\n", f(T, 1));
}
