시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 (추가 시간 없음) 512 MB111100.000%

문제

Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.

When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?

입력

N M
S1 D1
S2 D2
.
.
.
SM DM

The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.

출력

Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.

예제 입력 1

5 4
2 3
3 4
4 3
5 4

예제 출력 1

10

예제 입력 2

5 5
1 2
2 3
3 4
4 5
5 1

예제 출력 2

2

예제 입력 3

5 0

예제 출력 3

32