import Data.Graph.Inductive
import Control.Monad
import Data.List(foldl')
import qualified Data.List as L
import Data.Set
import qualified Data.Set as S

main = do
    [n_, m_] <- return . L.map read . words =<< getLine
    let readEdge = do
	    [a,b,c] <- return . L.map read . words =<< getLine
	    return (a,b,c)
    edges <- replicateM m_ readEdge
    let nodes = L.map (\i->(i,())) [1..n_]
	gr = mkGraph nodes edges	::Gr () Int
	edgeSet:: Set (Node,Node) -> LPath Int ->  Set (Node,Node)
	edgeSet set (LP []) = set
	edgeSet set (LP [node]) = set
	edgeSet set (LP ((nodeId1,_):(nodeId2,_):path)) =
	    edgeSet (insert (nodeId1,nodeId2) set) $ LP ((nodeId2,0::Int):path)
	rltree = msTree (undir gr)
	lastSet = L.foldl' edgeSet S.empty rltree
    print $ m_ - (size lastSet)