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
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

pair<vector<int>, int> Scc(const vector<vector<int>>& adj) {
    const int n = adj.size();
    vector<int> num(n, 0), low(n, 0), color(n, 0);
    vector<int> sta;
    vector<bool> inS(n, 0);
    int t = 0, colnum = 0;
    function<void(int)> visit = [&](int cur) {
        low[cur] = num[cur] = ++t;
        sta.emplace_back(cur); inS[cur] = 1;
        for(int nxt : adj[cur]) {
            if(num[nxt] == 0) {
                visit(nxt);
                low[cur] = min(low[cur], low[nxt]);
            } else if(inS[nxt])
              low[cur] = min(low[cur], num[nxt]);
        }
        if(low[cur] == num[cur]) {
            while(true) {
                int nxt = sta.back(); sta.pop_back(); inS[nxt] = false;
                color[nxt] = colnum;
                if(cur == nxt) break;
            }
            ++colnum;
        }
    };
    for(int v : in(n))
      if(num[v] == 0)
        visit(v);
    return make_pair(color, colnum);
}

vector<int> topologicalSort(const vector<vector<int>>& adj) {
    int N = adj.size();
    vector<int> deg(N);//??\?¬???°
    for(int i = 0; i < N; ++i)
      for(int nv : adj[i])
        ++deg[nv];
    vector<int> ord(N, -1);
    int t = 0;
    for(int v = 0; v < N; ++v) 
      if(deg[v] == 0)
        ord[t++] = v;
    for(int h = 0; h < t; ++h) {
        int v = ord[h];
        for(int nv : adj[v]) {
            --deg[nv];
            if(deg[nv] == 0)
              ord[t++] = nv;
        }
    }
    return ord;
}

using i64 = long long;
const i64 MOD = 1e9 + 7;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<vector<int>> __adj(n);
    for(int _ : in(m)) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        __adj[u].emplace_back(v);
    }
    vector<int> color; int col;
    tie(color, col) = Scc(__adj);
    vector<vector<int>> radj(col);
    for(int v : in(n))
      for(int u : __adj[v])
        if(color[v] != color[u])
          radj[color[u]].emplace_back(color[v]);
    for(auto& a : radj) {
        sort(a.begin(), a.end());
        a.erase(unique(a.begin(), a.end()), a.end());
    }
    vector<int> ord = topologicalSort(radj);
    vector<i64> dp(col, -1LL);
    i64 ans = 1LL;
    function<i64(int)> dfs = [&](int v) {
        assert(v != -1);
        i64& res = dp[v];
        if(res != -1LL) return res;
        res = 1LL;
        for(int u : radj[v])
          res = res * dfs(u) % MOD;
        return ++res;
    };
    for(int v : ord) {
        if(dp[v] != -1LL) continue;
        ans = ans * dfs(v) % MOD;
    }
    cout << ans << endl;
    return 0;
}