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
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

struct SCC
{
	vector<vector<int> > G;
	vector<vector<int> > rG;
	vector<int> vs;
	vector<bool> used;
	vector<int> cmp;
	int sz,newsz;
	SCC(int n):G(n),rG(n),used(n,false),cmp(n){sz = n;}
	
	void add_edge(int from,int to)
	{
		G[from].PB(to);
		rG[to].PB(from);
	}
	
	void dfs(int v)
	{
		used[v] = true;
		REP(i,G[v].size())
		{
			if(!used[G[v][i]])dfs(G[v][i]);
		}
		vs.PB(v);
	}
	
	void rdfs(int v,int k)
	{
		used[v] = false;
		cmp[v] = k;
		REP(i,rG[v].size())
		{
			if(used[rG[v][i]])rdfs(rG[v][i],k);
		}
	}
	
	int reMake()
	{

		vs.clear();
		REP(i,sz)if(!used[i])dfs(i);
		int k = 0;
		for(int i = sz-1;i >= 0;i--)
		{
			if(used[vs[i]])
			{
				rdfs(vs[i],k++);
			}
		}
		return newsz = k;
	}
	
	
	
	void makeList(vector<vector<int> > &v)
	{
		REP(i,sz)
		{
			REP(j,G[i].size())
			{
				if(cmp[i] == cmp[G[i][j]])continue;
				v[cmp[i]].PB(cmp[G[i][j]]);
			}
		}
	}

	void makeReverseList(vector<vector<int> > &v)
	{
		REP(i,sz)
		{
			REP(j,G[i].size())
			{
				if(cmp[i] == cmp[G[i][j]])continue;
				v[cmp[G[i][j]]].PB(cmp[i]);
			}
		}
	}
	
	int scc_node(int n)
	{
		return cmp[n];
	}
};


#define MOD 1000000007 

vector<vector<int> > v(1000);
vector<vector<int> > rv(1000);

bool check[10001];
ll dp[1111][2];

void dfs(int n)
{
	check[n] = true;
	
	if(rv[n].size() == 0)
	{
		dp[n][0] = 1;
		dp[n][1] = 1;
		return;
	}
	
	REP(i,rv[n].size())
	{
		dfs(rv[n][i]);
	}

	ll tmpa = 1;
	ll tmpb = 1;	
	REP(i,rv[n].size())
	{
		tmpa = (tmpa * ((dp[rv[n][i]][0]+dp[rv[n][i]][1])%MOD))%MOD;
		tmpb = (tmpb * dp[rv[n][i]][0])%MOD;
	}
	dp[n][0] = tmpb;
	dp[n][1] = tmpa;
	
	return;
}
	

int main()
{
	int n,m;cin >> n >> m;
	
	SCC scc(n);
	REP(i,m)
	{
		int a,b;cin >> a >> b;
		a--;b--;
		scc.add_edge(a,b);
	}
	
	scc.reMake();
	scc.makeList(v);
	scc.makeReverseList(rv);
	
	
	ll ans = 1;
	REP(i,scc.newsz)
	{
		if(v[i].size() == 0 && !check[i])
		{
			dfs(i);
			ans = (ans * (dp[i][0]+dp[i][1]))%MOD;
		}
	}		
	
	cout << ans << endl;
	
	return 0;
}