Link to this code:
https://cses.fi/paste/34027bad486c541efc8928/#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pp pop_back
#define ll long long
#define pb push_back
#define pq priority_queue
#define ls(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define wr cout << "------------------------" << endl
#define tt debug
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
vector<int>g[N];
int w[N][2];
int in[N];
signed main(){
#ifdef parad0x
freopen("file.in","r",stdin);
#endif
#define print(...) 42
ios::sync_with_stdio(false);cin.tie(nullptr);
int n,m;
cin >> n >> m;
for(int i = 1,a,b;i<=m;++i){
cin >> a >> b;
g[a].pb(b);
in[b] += 1;
}
queue<int>q;
for(int i = 1;i<=n;++i){
if(!in[i]){
q.push(i);
w[i][(i == 1)] = 1;
}
}
while(!q.empty()){
int nd = q.front();
q.pop();
for(auto it:g[nd]){
in[it] -= 1;
w[it][1] = (w[nd][1] + w[it][1] + w[nd][0] * (it == 1)) % MOD;
w[it][0] = (w[nd][0] + w[it][0]) % MOD;
if(!in[it]){
q.push(it);
}
}
}
cout << w[n][1] << endl;
return 0;
}