N,K = map(int,input().split()) lsA = [] lsg = [[] for i in range(N)] for i in range(N): A,M = map(int,input().split()) ls = list(map(int,input().split())) lsA.append(A) for j in range(len(ls)): lsg[ls[j]-1].append((i,lsA[i]-lsA[ls[j]-1])) for i in range(N-1): lsg[i].append((i+1,0)) cost = [0]*(N) for i in range(N): c = cost[i] for g,v in lsg[i]: cost[g] = max(cost[g],c+v) print(max(cost))