#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1005;
int main() {
  ios::sync_with_stdio(false);
  int N, T;
  cin >> N >> T;
  int ans = 0;
  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i].first >> A[i].second;
    A[i].first = T - A[i].first;
    ans = max(ans, A[i].second);
  }
  sort(A.begin(), A.end());
  for (int i = T; i > 0; --i) {
    vector<int> values;
    while (!A.empty() && A.back().first >= i) {
      values.push_back(A.back().second);
      ans = max(ans, values.back());
      A.pop_back();
    }
    values.push_back(0);
    sort(values.begin(), values.end());
    vector<int> taken;
    for (int j = values.size() - 1;
         j > 0 && (i > 10 || int(taken.size()) < (1 << i)); j -= 2) {
      taken.push_back(values[j] + values[j - 1]);
    }
    for (int p : taken) {
      ans = max(ans, p);
      A.push_back(make_pair(i - 1, p));
    }
  }
  cout << ans << '\n';
}
