n,m = map(int, input().split())
s = []
for _ in range(n):
n_ = int(input())
t = []
for _ in range(n_):
a,b = map(int, input().split())
t.append([a,b])
s.append(t)
f = [[0 for _ in range(m+1)] for _ in range(n)]
for i in range(n):
for j in range(m+1):
f[i][j] = f[i-1][j]
for v,w in s[i]:
if j >= v:
f[i][j] = max(f[i][j], f[i-1][j-v] + w)
print(f[n-1][m])