USES MATH;
var
f : array [-1..100,-1..100] of int64;
a,c : array [-1..100006] of longint;
i,n,k,j: longint;
const
fi = 'DRSEL.inp';
fo = 'DRSEL.out';
procedure doc;
begin
assign(input,fi); reset(input);
assign(output,fo); rewrite(output);
readln(n,k);
for i:=1 to n do
readln(a[i],c[i]);
end;
begin
doc;
for i:=1 to n do
for j:=1 to k do
if c[i]<=j then f[i,j]:=max(f[i-1,j],f[i-1,j-c[i]]+a[i]) else f[i,j]:=f[i-1,j];
write(f[n,k]);
close(input);
close(output);
end.