uses
  Math;

const
  maxn = 16;

type
  twork = record
    t, p, k, nn : integer;
    prev : array[1..maxn] of integer;
    done : boolean;
  end;

var
  n, m, i, j, time, nans, cost : integer;
  w : array[1..maxn] of twork;
  ans : array[1..maxn] of integer;
  added, can : boolean;
  tw : twork;

begin
  reset(input, 'rpg.in');
  rewrite(output, 'rpg.out');
  read(n, m);
  for i := 1 to n do begin
    read(w[i].t, w[i].p, w[i].k);
    w[i].nn := i;
    for j := 1 to w[i].k do begin
      read(w[i].prev[j]);
    end;
  end;
  for i := 1 to n do begin
    for j := i + 1 to n do begin
      if (w[i].p < w[j].p) then begin
        tw := w[i];
        w[i] := w[j];
        w[j] := tw;
      end;
    end;
  end;
  time := 0;
  nans := 0;
  cost := 0;
  added := true;
  while (added) do begin
    added := false;
    for i := 1 to n do begin
      if (not(w[i].done)) and (time + w[i].t <= m) then begin
        can := true;
        for j := 1 to w[i].k do begin
          if (not(w[w[i].prev[j]].done)) then begin
            can := false;
            break;
          end;
        end;
        if (can) then begin
          cost := cost + w[i].p;
          time := time + w[i].t;
          nans := nans + 1;
          ans[nans] := w[i].nn;
          added := true;
          w[i].done := true;
          break;
        end;
      end;
    end;
  end;
  writeln(cost);
  for i := 1 to nans do begin
    write(ans[i], ' ');
  end;
end.