#graph102. 受欢迎的牛
受欢迎的牛
Popular Cows
Problem Source
HAOI 2006
Problem Description
Every cow's dream is to become the most popular cow.
Now there are cows. You are given pairs of integers , meaning cow thinks cow is popular. This relation is transitive: if thinks is popular and thinks is popular, then also thinks is popular. Your task is to find out how many cows are considered popular by all the cows.
Input Format
The first line contains two integers (). The next lines each contain two integers , meaning thinks is popular. (The information may be repeated, i.e. the same pair may appear multiple times.)
Output Format
Output one number: how many cows are considered popular by all the cows.
Sample Input
3 3
1 2
2 1
2 3
Sample Output
1