#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<ll> dp(n);
    dp[0] = 0;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];

        int m;
        cin >> m;

        if (i == 0) continue;
        ll t = dp[i - 1];

        for (int j = 0; j < m; j++) {
            int b;
            cin >> b;
            b--;

            t = max(t, dp[b] - a[b] + a[i]);
        }
        dp[i] = t;
    }
    cout << dp[n - 1] << endl;

    return 0;
}