import sys readline = sys.stdin.readline N, K = map(int, readline().split()) inf = 10 ** 18 dp = [-inf] * N dp[0] = 0 A = [0] * N for i in range(N): if i: dp[i] = max(dp[i], dp[i - 1]) A[i], M = map(int, readline().split()) B = list(map(int, readline().split())) for b in B: dp[i] = max(dp[i], dp[b - 1] + A[i] - A[b - 1]) print(dp[-1])