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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

const ll MOD = 1e9+7;

//verified AOJ GRL_3
#define MAX_V 1000
vector<int> G[MAX_V];   //辺
vector<int> rG[MAX_V];  //逆辺
vector<string> str;

void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v, bool used[MAX_V], vector<int> &vs){     //末端から遠いノードから順に、たどり着けるノードをvsに入れていく
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[MAX_V]){   //逆辺を使って末端に近いノードから順にDFS
    used[v] = true;
    sccs.push_back(v);
    cmp[v] = k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector< vector<int> > &each_scc, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    rep(i,MAX_V)used[i] = false;
    vs.clear();
    rep(v,V){
        if(!used[v]) dfs(v, used, vs);
    }
    
    rep(i,MAX_V) used[i] = false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i], k++, sccs, cmp, used);
            each_scc.push_back(sccs);
        }
    }
    return k;
}

void getSccedGraph(vector<vector<int>> each_scc, vector<int> cmp, vector<int> newGraph[MAX_V]){   //sccの結果からグラフを得る O(E)くらい？ verified ARC030-C
    rep(i,each_scc.size()){
        set<int> edges;
        rep(j,each_scc[i].size()){
            rep(k,G[each_scc[i][j]].size()){
                int to = G[each_scc[i][j]][k];
                if( cmp[to]!=i )edges.insert(cmp[to]);
            }
        }
        for(auto &edge:edges)newGraph[i].pb(edge);
    }
}

vector<int> nG[MAX_V], rnG[MAX_V];

ll dp[MAX_V];
ll dfs(int cur){
    if(dp[cur]!=-1)return dp[cur];
    if(rnG[cur].size()==0)return dp[cur] = 2;
    
    ll ret = 1;
    for(auto e:rnG[cur]){
        (ret *= dfs(e))%=MOD;
    }
    
    return dp[cur] = (ret+1)%MOD;
}


int main(){
    rep(i,MAX_V)dp[i] = -1;
    int v,e;
    cin>>v>>e;
    
    rep(i,e){
        int s,t;
        cin>>s>>t;
        s--,t--;
        
        add_edge(s,t);
    }
    vector<vector<int>> each_scc;  //それぞれの強連結成分のリスト
    vector<int> cmp(MAX_V);        //あるノードが属している強連結成分の番号( 多分each_sccに対応している )
    int k = scc(v,each_scc,cmp);   //強連結成分の個数
    
    getSccedGraph(each_scc, cmp, nG);
    
    rep(i,MAX_V){
        for(auto e:nG[i]){
            rnG[e].pb(i);
        }
    }
    
    vector<int> zero_deg;
    rep(i,k){
        if(nG[i].size()==0)zero_deg.pb(i);
    }
    
    
    ll ans = 1;
    for(auto elm:zero_deg){
        (ans *= dfs(elm))%=MOD;
    }
    cout<<ans<<endl;
    
}

