class SparseMatrix
	def initialize(m, n)
		@m, @n = m, n
		@rows = (1..m).map{ Hash.new(0) }
	end

	def [](i)
		@rows[i]
	end

	def rank
		save = Marshal.load(Marshal.dump(self))
		rank = 0
		j = 0
		(0..@m-1).each{|i|
			pivot_idx = nil
			j += 1 until j >= @n || pivot_idx = @rows.index{|row| row[j] && row[j] != 0}
			break if j >= @n
			rank += 1

			pivot_row = @rows.delete_at(pivot_idx)
			a = pivot_row[j]
			
			@rows.each{|row|
				b = row[j]
				if b && b != 0
					r = b / a
					pivot_row.each{|k, val|
						row[k] -= r * val
						row.delete(k) if row[k] == 0
					}
				end
			}

			j += 1
		}		
		@rows = save.rows
		rank
	end

	attr_reader :rows
end

require 'mathn'
n, m = gets.split.map &:to_i
mat = SparseMatrix.new(n, m)
m.times{|k|
	i, j = gets.split.map &:to_i
	mat[i-1][k] = -1
	mat[j-1][k] = 1
}
p m - mat.rank