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;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

using Graph = vector<vector<int>>;

// O(|V| + |E|)
struct SCC
{
    int V, K;
    Graph G, rG;
    vector<int> vs;
    vector<bool> used;
    vector<int> cmp;
    SCC(int _V) : V(_V), G(_V), rG(_V), used(_V, false), cmp(_V) {}
    void add_edge(int from, int to)
    {
        G[from].push_back(to);
        rG[to].push_back(from);
    }
    void dfs(int cur)
    {
        used[cur] = true;
        for (const auto &v : G[cur])
        {
            if (!used[v])
                dfs(v);
        }
        vs.push_back(cur);
    }
    void rdfs(int cur, int k)
    {
        used[cur] = true;
        cmp[cur] = k;
        for (const auto &v : rG[cur])
        {
            if (!used[v])
                rdfs(v, k);
        }
    }
    vector<int> scc()
    {
        for (int i = 0; i < V; i++)
            used[i] = false;
        vs.clear();
        for (int v = 0; v < V; v++)
        {
            if (!used[v])
                dfs(v);
        }
        for (int i = 0; i < V; i++)
            used[i] = false;
        int k = 0;
        for (int i = (int)vs.size() - 1; i >= 0; i--)
        {
            if (!used[vs[i]])
                rdfs(vs[i], k++);
        }
        K = k;
        return cmp;
    }
    Graph buildGraph()
    {
        scc();
        vector<set<int>> s(K);
        Graph ret(K);
        for (int v = 0; v < V; v++)
        {
            for (const auto to : G[v])
            {
                s[cmp[v]].insert(cmp[to]);
            }
        }
        for (int i = 0; i < K; i++)
        {
            for (auto j : s[i])
            {
                if (i != j)
                    ret[i].push_back(j);
            }
        }
        return ret;
    }
};

int N, M;

ll dfs(const Graph &g, int cur)
{
    ll res = 1;
    for (const auto &v : g[cur])
    {
        res *= (dfs(g, v) + 1);
        res %= MOD;
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    SCC scc(N);
    for (int i = 0; i < M; i++)
    {
        int s, d;
        cin >> s >> d;
        s--;
        d--;
        scc.add_edge(d, s);
    }
    Graph g = scc.buildGraph();
    ll res = 1;
    int K = g.size();
    vector<int> in(K, 0);
    for (int i = 0; i < K; i++)
    {
        for (const auto &v : g[i])
        {
            in[v]++;
        }
    }
    for (int i = 0; i < K; i++)
    {
        if (in[i])
            continue;
        res *= (dfs(g, i) + 1LL);
        res %= MOD;
    }
    cout << res << endl;
}

