#include using namespace std; using ll = long long; #include "atcoder/modint.hpp" using mint = atcoder::modint998244353; struct UnionFind { int n; vector par; vector> member; vector add; vector val; UnionFind(int n) : n(n), par(n, -1), member(n), add(n), val(n, 0) { for (int i = 0; i < n; i++) member[i].push_back(i); } int find(int x) { if (par[x] < 0) return x; return par[x] = find(par[x]); } void unite(int u, int v) { u = find(u); v = find(v); if (u == v) return; if (par[u] > par[v]) swap(u, v); par[u] += par[v]; par[v] = u; mint d = add[v] - add[u]; for (auto x : member[v]) { member[u].push_back(x); val[x] += d; } } bool same(int u, int v) { return find(u) == find(v); } mint get_val(int u) { return val[u] + add[find(u)]; } void add_val(int u, mint x) { add[find(u)] += x; } }; void solve() { int n, m; cin >> n >> m; vector E(n, vector()); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; E[v - 1].emplace_back(u - 1); } UnionFind UF(n); mint ans = 0; for (int v = 0; v < n; v++) { sort(E[v].begin(), E[v].end()); mint add = 1; for (auto u : E[v]) { if (!UF.same(u, v)) { add += UF.get_val(u); UF.unite(u, v); } } UF.add_val(v, add); ans += add; } cout << ans.val() << endl; } int main() { solve(); }