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>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
using ll = long long;
const int INF = 1e9;

template <typename T> struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T> >;
template <typename T> using WeightedGraph = vector<Edges<T> >;
using UnWeightedGraph = vector<vector<int> >;

template <typename G> struct StronglyConnectedComponents {
    const G &g;
    UnWeightedGraph gg, rg;
    vector<int> comp, order, used;

    StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
        for (int i = 0; i < g.size(); i++) {
            for (auto e : g[i]) {
                gg[i].emplace_back((int)e);
                rg[(int)e].emplace_back(i);
            }
        }
    }

    int operator[](int k) { return comp[k]; }

    void dfs(int idx) {
        if (used[idx]) return;
        used[idx] = true;
        for (int to : gg[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if (comp[idx] != -1) return;
        comp[idx] = cnt;
        for (int to : rg[idx]) rdfs(to, cnt);
    }

    void build(UnWeightedGraph &t) {
        for (int i = 0; i < gg.size(); i++) dfs(i);
        reverse(begin(order), end(order));
        int ptr = 0;
        for (int i : order)
            if (comp[i] == -1) rdfs(i, ptr), ptr++;

        t.resize(ptr);
        for (int i = 0; i < g.size(); i++) {
            for (auto &to : g[i]) {
                int x = comp[i], y = comp[to];
                if (x == y) continue;
                t[x].push_back(y);
            }
        }
    }
};
constexpr int MOD = 1e9 + 7;
int dfs(int n, UnWeightedGraph &T) {
    if (T[n].size() == 0) return 2;
    int ret = 1;
    for (auto nxt : T[n]) {
        ret *= dfs(nxt, T);
        ret %= MOD;
    }
    return (ret + 1) % MOD;
}
bool solve() {
    int N, M;
    cin >> N >> M;
    if (N == 0) return false;
    UnWeightedGraph G(N), T;
    REP(i, M) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[v].push_back(u);
    }

    StronglyConnectedComponents<UnWeightedGraph> scc(G);
    scc.build(T);
    int K = T.size();
    vector<int> deg(K);
    int root = 0;
    REP(i, K) {
        for (auto nxt : T[i]) {
            deg[nxt]++;
        }
    }
    ll ans = 1;
    vector<int> roots;
    REP(i, K) {
        if (deg[i] == 0) roots.push_back(i);
    }
    for (auto root : roots) {
        ans *= dfs(root, T);
        ans %= MOD;
    }
    cout << ans << endl;
    return true;
}

signed main() {
    solve();
    // while (solve())
    //     ;
}

