#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int w[N], f[N];
int n, V, a, b;
int main()
{
cin >> n >> V;
for(int i = 1; i <= n; i ++) cin >> a >> b, w[a] = max(w[a], b);//体积为a的包最大价值
for(int i = 1; i <= V; i ++)
for(int j = 1; j <= i; j ++) f[i] = max(f[i-j] + w[j], f[i]);//总体积为i的最大价值
cout << f[V];
}