{
TASK:store
LANG:Pascal
}
program store;

var Matrix: array[1..10000,1..10000] of Boolean;
    weighted: array[1..10000] of Boolean;
    Weight: array[1..10000] of Integer;
    Rooms: array[1..10000] of Byte;
    avail: array[1..10000] of Boolean;
    ElapsedTime, test: Integer;
    N, M: Integer;

procedure Input;
var iRoom, iChield, Chields, ChieldID: Integer;
begin
 ReadLn(N,M);

 for iRoom := 1 to N do begin
  Read(Rooms[iRoom]);
  Read(Chields);

  If (Chields > 0) then begin
   for iChield := 1 to Chields do begin
    Read(ChieldID);
    Matrix[iRoom,ChieldID] := True;
   end;
  end;

  ReadLn;
 end;
end;

procedure DoWeight(aRoom, aWeight: Integer);
var iRoom: Integer;
begin
 Weight[aRoom] := aWeight;
 weighted[aRoom] := True;

 for iRoom := 1 to N do begin
  If (Matrix[aRoom,iRoom]) and not(weighted[iRoom]) then DoWeight(iRoom,aWeight + 1);
 end;
end;

function FindFarthestOfRoom(aRoom: Integer): Integer;
var iRoom, MaxDis, Maximed, Dis: Integer;
begin
 Maximed := aRoom;
 MaxDis := 0;
 for iRoom := 1 to N do begin
  If (Matrix[aRoom,iRoom]) then begin

   Dis := FindFarthestOfRoom(iRoom);
   If (Weight[Dis] > MaxDis) and (Rooms[Dis] > 0) then begin
    MaxDis := Weight[Dis];
    Maximed := Dis;
   end;

  end;
 end;
 FindFarthestOfRoom := Maximed;
end;

function Min(a, b: Integer): Integer;
begin
 If (a < b) then Min := a
 else Min := b;
end;

procedure GoBackCar(var aCarPos: Integer);
var iRoom: Integer;
begin
 for iRoom := 1 to N do begin
  If (Matrix[iRoom,aCarPos]) then begin
   aCarPos := iRoom;
   Exit;
  end;
 end;
end;

function AllIsPaid: Boolean;
var iRoom: Integer;
begin
 AllIsPaid := False;
 for iRoom := 2 to N do begin
  If (Rooms[iRoom] > 0) then Exit;
 end;
 AllIsPaid := TRue;
end;

procedure GoGoCar;
var CarHas, CarPos, CarTake: Integer;
    goRoom: Integer;
    DoExit: Boolean;
begin
 DoExit := False;
 CarHas := 0;
 CarPos := 1;
 ElapsedTime := 0;

 while (True) do begin
  while (CarHas < M) do begin
   goRoom := FindFarthestOfRoom(CarPos);
   If not(goRoom = CarPos) then begin
    CarTake := min(Rooms[goRoom],M - CarHas);
    Inc(CarHas,CarTake);
    Dec(Rooms[goRoom],CarTake);
    Inc(ElapsedTime,Weight[goRoom] - Weight[CarPos]);
    CarPos := goRoom;
   end;
   If not(CarPos = 1) then begin
    Inc(ElapsedTime);
    GoBackCar(CarPos);
    CarTake := min(Rooms[CarPos],M - CarHas);
    Inc(CarHas,CarTake);
    Dec(Rooms[CarPos],CarTake);
   end;
   If (CarPos = 1) then Break;
   If (AllIsPaid) then begin
    DoExit := True;
    Break;
   end;
  end;

  Inc(ElapsedTime,Weight[CarPos]);
  CarHas := 0;
  CarPos := 1;
  If (DoExit) then Exit;
  If (AllIsPaid) then Exit;
 end;
end;

begin
 FillChar(Matrix,SizeOf(Matrix),False);
 Input;

 FillChar(weighted,SizeOf(weighted),False);
 FillChar(Weight,SizeOf(Weight),0);
 FillChar(avail,SizeOf(avail),True);
 Rooms[1] := 0;
 DoWeight(1,0);

 GoGoCar;

 WriteLn(ElapsedTime mod 1000000000);
end.
