import collections
N, V = map(int, input().split())
v = collections.defaultdict(list)
w = collections.defaultdict(list)
for i in range(N):
m = int(input())
for _ in range(m):
a, b = map(int, input().split())
v[i].append(a)
w[i].append(b)
dp = [0 for i in range(V+1)]
for i in range(N):
for j in range(V, -1, -1):
for k in range(len(v[i])):
if j >= v[i][k]:
dp[j] = max(dp[j-v[i][k]]+w[i][k], dp[j])
print(max(dp))