(n,m)=gets.split.map(&:to_i)
xyz=ARGF.map {|s|s.split.map(&:to_i)}
xy=xyz.map{|x,y|[x,y]}



tmp=(1..n).to_a



xy.each{|x,y|
    (0...n).each{|i|
        if(tmp[i]==x)
            tmp[i]=y
        end
    }
}

p tmp.uniq.size


