//  Задача "Ролевая игра" 
//  Седьмая командная Интернет-олимпиада сезона 2009-2010.
//  Автор задачи - Рустам Ганеев, ganeev@rain.ifmo.ru
//  Автор решения - Нияз Нигматуллин, nigmatullin@rain.ifmo.ru
//

import java.io.*;
import java.util.*;

public class rpg_nn implements Runnable {
    public static void main(String[] args) {
        new rpg_nn().run();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        boolean eof;
        String buf;

        public FastScanner(String fileName) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(fileName));
            nextToken();
        }

        public FastScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            nextToken();
        }

        String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    eof = true;
                    break;
                }
            }
            String ret = buf;
            buf = eof ? "-1" : st.nextToken();
            return ret;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        void close() {
            try {
                br.close();
            } catch (Exception e) {

            }
        }

        boolean isEOF() {
            return eof;
        }
    }

    FastScanner sc;
    PrintWriter out;

    private static final String FN = "rpg";

    public void run() {
        Locale.setDefault(Locale.US);
        try {
            sc = new FastScanner(FN + ".in");
            out = new PrintWriter(FN + ".out");
            solve();
            sc.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    void doAssert(boolean isRight, String s) {
        if (!isRight)
            throw new AssertionError(s);
    }

    final int MAXN = 16;
    final int MAXM = 1000;
    final int MAXP = 1000;

    private void solve() {
        int n = sc.nextInt();
        int m = sc.nextInt();
        doAssert(1 <= n && n <= MAXN, "n is out of range");
        doAssert(1 <= m && m <= MAXM, "m is out of range");
        int[] d = new int[n];
        int[] t = new int[n];
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
            p[i] = sc.nextInt();
            doAssert(1 <= t[i] && 1 <= p[i] && t[i] <= MAXM && p[i] <= MAXP,
                    "time and/or experience is out of range, line #" + (i + 1));
            int k = sc.nextInt();
            doAssert(0 <= k && k <= n, "k[" + (i + 1) + "] is out of range");
            for (int j = 0; j < k; ++j) {
                int x = sc.nextInt();
                doAssert(1 <= x && x <= n,
                        "dependency is not in the range 1..n, line #" + (i + 1)
                                + ", number #" + (j + 1));
                d[i] |= 1 << (x - 1);
            }
        }
        int[] dp = new int[1 << n];
        Arrays.fill(dp, Integer.MIN_VALUE / 10);
        dp[0] = 0;
        int[] timeForMask = new int[1 << n];
        for (int i = 1; i < 1 << n; i++) {
            timeForMask[i] = timeForMask[i - Integer.highestOneBit(i)]
                    + t[Integer.numberOfTrailingZeros(Integer.highestOneBit(i))];
        }
        int ans = 0;
        int mask = 0;
        for (int i = 1; i < 1 << n; i++) {
            if (timeForMask[i] > m) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if ((((i >> j) & 1) == 0) || (i & d[j]) != d[j]) {
                    continue;
                }
                dp[i] = Math.max(dp[i], dp[i ^ (1 << j)] + p[j]);
            }
            if (ans < dp[i]) {
                ans = dp[i];
                mask = i;
            }
        }
        ArrayList<Integer> answer = new ArrayList<Integer>();
        wh: while (mask > 0) {
            for (int i = 0; i < n; i++) {
                if (((mask >> i) & 1) == 1 && (mask & d[i]) == d[i]
                        && dp[mask ^ (1 << i)] + p[i] == dp[mask]) {
                    answer.add(i);
                    mask ^= 1 << i;
                    continue wh;
                }
            }
            throw new AssertionError("couldn't restore the answer");
        }
        Collections.reverse(answer);
        out.println(ans);
        for (int i : answer) {
            out.print((1 + i) + " ");
        }
    }
}
