include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
int f[1010][1010];
int v[1010], w[1010];
for (int i = 1; i <= n; i) cin >> v[i] >> w[i];
for (int i = 1; i <= n; i)
{
for (int j =0; j <= m; j++)
{
f[i][j] = f[i - 1][j];
if (j >= v[i])
{
f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]);
}
}
}
cout << f[n][m] << endl;
return 0;
}