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

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

public class rpg_nn_tle implements Runnable {
    public static void main(String[] args) {
        new rpg_nn_tle().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);
    }

    private void solve() {
        int n = sc.nextInt();
        int m = sc.nextInt();
        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();
            int k = sc.nextInt();
            for (int j = 0; j < k; ++j) {
                int x = sc.nextInt();
                d[i] |= 1 << (x - 1);
            }
        }
        int[][] dp = new int[m + 1][1 << n];
        for (int i = 0; i <= m; i++) {
            Arrays.fill(dp[i], Integer.MIN_VALUE / 10);
            dp[i][0] = 0;
        }
        int ans = 0;
        int mask = 0;
        int time = 0;
        for (int i = 1; i < 1 << n; i++) {
            for (int e = 0; e <= m; ++e) {
                for (int j = 0; j < n; j++) {
                    if (e < t[j] || (((i >> j) & 1) == 0) || (i & d[j]) != d[j]) {
                        continue;
                    }
                    dp[e][i] = Math.max(dp[e][i], dp[e - t[j]][i ^ (1 << j)]
                            + p[j]);
                }
                if (ans < dp[e][i]) {
                    ans = dp[e][i];
                    mask = i;
                    time = e;
                }
            }
        }
        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[time - t[i]][mask ^ (1 << i)] + p[i] == dp[time][mask]) {
                    answer.add(i);
                    mask ^= 1 << i;
                    time -= t[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) + " ");
        }
    }
}
