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?



Input

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.

Output

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

Examples

Input

5 4
2 3
3 4
4 3
5 4


Output

10


Input

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


Output

2


Input

5 0


Output

32
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int N,M;
vi g[1010],r[1010];
int used[1010];
int List[1010],l;
int cycle[1010],c;
int inCycle[1010];
ll dp[1010];

void dfs(int cur){
	if(used[cur]){
		int from = 0;
		while(List[from] != cur) from++;
		rep2(i,from,l){
			cycle[c++] = List[i];
		}
		return;
	}
	used[cur] = 1;
	List[l++] = cur;
	if(sz(g[cur]) == 0){
		cycle[c++] = cur;
		return;
	}
	rep(i,sz(g[cur])){
		dfs(g[cur][i]);
	}
}

ll solve(int v){
	ll& res=dp[v];
	if(res != -1)return res;
	used[v] = 1;
	res = 1;
	rep(i,sz(r[v])){
		res = res * solve(r[v][i]) % MOD;
	}
	res = (res+1) % MOD;
	return res;
}

ll f(int start){
	l=0;
	c=0;
	dfs(start);
	ll res = 1;
	rep(i,c)inCycle[cycle[i]] = 1;
	rep(i,c)rep(j,sz(r[cycle[i]])){
		if(inCycle[r[cycle[i]][j]])continue;
		res = res * solve(r[cycle[i]][j]) % MOD;
	}
	res = (res+1) % MOD;
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>M;
	rep(i,M){
		int s,d;
		cin>>s>>d;
		s--;d--;
		g[s].pb(d);
		r[d].pb(s);
	}

	memset(dp,-1,sizeof(dp));
	ll ans = 1;
	rep(i,N)if(!used[i]){
		ans = ans * f(i) % MOD;
	}
	cout<<ans<<endl;
}