cho.sh
Notes
Loading...

Height Order

Time limit

1s

Memory limit

128 MB

Problem

There are N students numbered from 1 to N. Every student has a different height, and only some pairs of students have been compared.

The comparison results are transitive. If one student is shorter than a second student, and the second student is shorter than a third student, then the first student is also shorter than the third student.

A student's exact rank by height is known if, for every other student, it can be determined whether that other student is shorter or taller. Given the comparison results, compute how many students can determine their exact height rank.

Input

The first line contains the number of students N (2 ≤ N ≤ 500) and the number of height comparisons M (0 ≤ M ≤ N(N-1)/2).

Each of the next M lines contains two distinct student numbers a and b, both between 1 and N. This means student a is shorter than student b.

Output

Print the number of students whose exact height rank can be determined from the given comparisons.