<?php
fscanf(STDIN,"%d %d",$N,$M);

for($i=1;$i<=$M;$i++){  
  ${"array".$i} = explode(" ",fgets(STDIN));
}

if($N-1 === $M){
  echo 0;
}else{
  $arrayResult = array();
  $arrayNumber = array();
  $arrayResult[1] = 0;
//  $arrayNumber[1] = 1;
  $result = 0;
  for($i=1;$i<=$M;$i++){
    $x = ${"array".$i}[0];
    $y = ${"array".$i}[1];
    $z = ${"array".$i}[2];
    if(array_key_exists($y,$arrayResult)){      
      if($z >= $arrayResult[$x]+$arrayResult[$y]){
//        $arrayResult[$y] = $arrayResult[$x]+$arrayResult[$y];
        $result++;
      }elseif(${"array".$arrayNumber[$y]}[2] >= $arrayResult[${"array".$arrayNumber[$y]}[0]]+$arrayResult[$x]+$z){
        $result++;
      }else{
//        $arrayResult[$y] = $arrayResult[$x]+$z;
      }
      //☆　>=対応
      if($arrayResult[${"array".$arrayNumber[$y]}[0]]+${"array".$arrayNumber[$y]}[2] > $arrayResult[$x]+$z){
        $arrayResult[$y] = $arrayResult[$x]+$z;
        $arrayNumber[$y] = $x;
      }
    }else{
      $arrayResult[$y] = $arrayResult[$x]+$z;
      $arrayNumber[$y] = $x;
    }
  }
  echo $result;
}
