#include using namespace std; typedef long long ll; const int INF = 1000000100; const ll INFL = 2e18; template bool chmin(T &a, T b){ if (a > b) { a = b; return true;} else return false;} template bool chmax(T &a, T b){ if (a < b) { a = b; return true;} else return false;} int main() { int N,K; cin >> N >> K; vector A(N); vector> B(N); for (int i = 0;i < N;i++) { cin >> A[i]; int M; cin >> M; for (int j = 0;j < M;j++) { int b; cin >> b; b--; B[i].push_back(b); } } vector dp(N,0); for (int i = 1;i < N;i++) { chmax(dp[i],dp[i-1]); for (int j = 0;j < B[i].size();j++) { chmax(dp[i],dp[B[i][j]] + A[i] - A[B[i][j]]); } } cout << dp[N-1] << endl; }