[n,v]=map(int, input().split())
groups=[[] for i in range(n)]
cnts=[]
for i in range(n):
cnt=int(input())
cnts.append(cnt)
for _ in range(cnt):
groups[i].append([int(x) for x in input().split()])
memory=[0]*(1+v)
for i1 in range(n):
for i2 in range(v,-1,-1):
tmp=memory[i2]
for i3 in range(cnts[i1]):
if i2>=groups[i1][i3][0]:
tmp=max(tmp,memory[i2-groups[i1][i3][0]]+groups[i1][i3][1])
memory[i2]=tmp
print(memory[-1])