from sys import stdin n, m, *indata = map(int, stdin.read().split()) offset = 0 pricetable = [0 for i in range(n+1)] dp = [0 for i in range(n+1)] for i in range(n): a, m = indata[offset],indata[offset + 1] offset += 2 dp[i+1] = dp[i] for j in range(m): b = indata[offset + j] dp[i+1] = max(dp[i+1],dp[b]-pricetable[b]+a) pricetable[i+1] = a offset += m print("{}".format(dp[n]))