import Data.Graph.Inductive
import Data.Graph.Inductive.Example( genUNodes)
import Control.Monad
import Data.List(foldl', sort)
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 
	gr = undir $ mkGraph (genUNodes n_) edges	::Gr () Int
	edgeSet:: Set (Node,Node) -> LPath Int ->  Set (Node,Node)
	edgeSet set (LP []) = set
	edgeSet set (LP [node]) = set
	edgeSet set (LP ((nId1,_):tl@((nId2,_):path))) = let
		nmax = max nId1 nId2
		nmin = min nId1 nId2
	    in edgeSet (insert (nmin,nmax) set) (LP tl)
	rtrees = [spTree nd gr | nd<-nodes gr]
	lastSet = L.foldl' edgeSet S.empty $ concat rtrees
    print $ m_ - (size lastSet)