{
TASK:capital
LANG:pascal
}
const inf=100000;
type connections=Record
        x,y,dist:Longint;
     End;
var con:Array[1..40000]of connections;
    len:Array[1..10000]of Longint;
    nearest:Array[1..10000]of Boolean;
    n,k,i,j,l,td,a,b,raz,br:Longint;
Begin
  ReadLn(n,k);
 Repeat
   ReadLn(a,b,raz);
  if (a>0)and(b>0)and(raz>0) then
  Begin
    l:=l+1;
    con[l].x:=a;
    con[l].y:=b;
    con[l].dist:=raz;
  End;
 Until (a=0)and(b=0)and(raz=0);
 len[1]:=0;
 For i:=2 to n do len[i]:=inf;
 For i:=1 to l do
 Begin
  if (con[i].x=1) then
  Begin
    len[con[i].y]:=con[i].dist;
   if con[i].dist<=k then nearest[con[i].y]:=True;
  End;
  if (con[i].y=1) then
  Begin
    len[con[i].x]:=con[i].dist;
   if con[i].dist<=k then nearest[con[i].x]:=True;
  End;
 End;
 For td:=1 to 19 do
 Begin
  For i:=1 to l do
  Begin
    if nearest[con[i].x] then
    for j:=1 to l do
    Begin
      if (con[j].x=con[i].x) then
      Begin
       if (len[con[j].y]>len[con[i].x]+con[j].dist)and
       (len[con[i].x]+con[j].dist<=k)then
       Begin
         len[con[j].y]:=len[con[i].x]+con[j].dist;
         nearest[con[j].y]:=True;
       End;
      End;
      if (con[j].y=con[i].x) then
      Begin
       if (len[con[j].x]>len[con[i].x]+con[j].dist)and
       (len[con[i].x]+con[j].dist<=k)then
       Begin
         len[con[j].x]:=len[con[i].x]+con[j].dist;
         nearest[con[j].x]:=True;
       End;
      End;
    End;
    if nearest[con[i].y] then
    for j:=1 to l do
    Begin
      if (con[j].x=con[i].y) then
      Begin
       if (len[con[j].y]>len[con[i].y]+con[j].dist)and
       (len[con[i].y]+con[j].dist<=k)then
       Begin
         len[con[j].y]:=len[con[i].y]+con[j].dist;
         nearest[con[j].y]:=True;
       End;
      End;
      if (con[j].y=con[i].y) then
      Begin
       if (len[con[j].x]>len[con[i].y]+con[j].dist)and
       (len[con[i].y]+con[j].dist<=k)then
       Begin
         len[con[j].x]:=len[con[i].y]+con[j].dist;
         nearest[con[j].x]:=True;
       End;
      End;
    End;
  End;
 End;
  br:=n;
 For i:=1 to n do
 if nearest[i] then br:=br-1;
  WriteLn(br-1);
End.