n, m = gets.chomp.split(" ").map(&:to_i) hash = Hash.new(0) count = 0 arr = [] n.times do b, c = gets.chomp.split(" ").map(&:to_i) arr << [b,c] # count += 1 if hash[c] >= 1 # count -= 1 if iru[c] == b && hash[c] >= 1 # iru[c] = b # hash[c] += 1 end arr = arr.uniq arr.each do |i,j| count += 1 if hash[j] >= 1 hash[j] += 1 end puts count