<?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();
  $arrayResult2 = array();
  $arrayResult[1] = 0;
  $arrayResult2[1] = 0;
  $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)){      
      $value = 0;
      if($z >= $arrayResult2[$x]+$arrayResult2[$y]){
        $arrayResult2[$y] = $arrayResult2[$x]+$arrayResult2[$y];
        $result++;
      }else{
//        $arrayResult[$y] = $arrayResult[$x]+$z;
      }
    }else{
      $arrayResult[$y] = $arrayResult[$x]+$z;
      $arrayResult2[$y] = $arrayResult[$x]+$z;
    }
  }
  echo $result;
}
