Under construction

Still being built. Things may change

Gomgomi's Last-Minute Cramming

Time limit1sMemory limit1024 MB

Summary
Count the orders for watching N lectures under prerequisite relations that form a forest, modulo 10^9+7.
Level

Medium6 of 10

Topics
Tree, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

곰곰: 파스스

With the final exam approaching, Gomgomi has NN backlogged lectures to watch. The lectures are numbered from 11 to NN in order. Each lecture has at most one lecture that must be watched before it. Gomgomi writes this relation as a→ba \rightarrow b, meaning lecture aa must be watched before lecture bb. The relations contain no cycles. The order in which Gomgomi watches all the lectures depends on these relations. Find the number of orders for watching all the lectures. Since the answer can be large, print it modulo 109+710^9+7.

Input

The first line contains the number of lectures NN and the number of relations MM. (0≤M<N≤200 000)(0 \leq M \lt N \leq 200\,000)

Each of the next MM lines contains integers aa and bb, separated by a space. (1≤a,b≤N;a≠b)(1 \leq a, b \leq N; a \neq b) This means lecture aa must be watched before lecture bb. The relations contain no cycles, and each lecture has at most one lecture that must be watched before it.

Output

Print the number of orders for watching all the lectures, modulo 109+710^9+7.

Examples3

  1. Example 1

    Input
    5 4
    1 2
    2 4
    2 5
    4 3
    
    Expected output
    3
    
  2. Example 2

    Input
    4 2
    1 2
    3 4
    
    Expected output
    6
    
  3. Example 3

    Input
    2 0
    
    Expected output
    2