#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int dp[105][MAXN];
int w[105][MAXN];
int c[105];
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    w[t - a][c[t - a]++] = b;
  }
  for (int i = t - 1; i >= 0; i--) {
    for (int j = 1; j <= 500; j++) {
      dp[i][j] = max(dp[i + 1][j << 1], dp[i + 1][(j << 1) - 1]);
    }
    for (int j = 0; j < c[i]; j++) {
      for (int k = n - 1; k >= 0; k--) {
        dp[i][k + 1] = max(dp[i][k + 1], dp[i][k] + w[i][j]);
      }
    }
  }
  printf("%d\n", dp[0][1]);
  return 0;
}
