func_code_string: #include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 13;   int n, m;   set<int> e[N];   set<pair<int, int> > q;   int p[N];   int tin[N], cnt, w[N], ans;   int gcd(int a, int b) { return (!a ? b : gcd(b % a, a)); }   void init() {     for (int i = 0; i < N; ++i) p[i] = i;   }   int find(int u) {     if (p[u] == u) return u;     return p[u] = find(p[u]);   }   void uni(int a, int b) {     a = find(a);     b = find(b);     if (a == b) return;     if (e[a].size() < e[b].size()) swap(a, b);     for (int to : e[b]) e[a].insert(find(to));     p[b] = a;     e[b].clear();   }   void print(int ans) {     printf( %d n , ans);     exit(0);   }   pair<int, int> getMax() {     auto it = q.end();     --it;     pair<int, int> res = (*it);     return res;   }   void merge(int id) {     if (id != find(id)) return;     vector<int> ver;     for (int v : e[id]) ver.push_back(find(v));     e[id].clear();     for (int i = 0; i < ver.size(); ++i) {       int pi = find(ver[i]);       q.erase(make_pair(e[pi].size(), pi));     }     for (int i = 1; i < ver.size(); ++i) uni(ver[i], ver[i - 1]);     int lv = find(ver[0]);     id = find(id);     e[id].insert(lv);     q.insert(make_pair(e[lv].size(), lv));     q.insert(make_pair(e[id].size(), id));     if (e[id].find(id) != e[id].end()) print(1);   }   void compress() {     for (int i = 0; i < n; ++i) {       q.insert(make_pair(e[i].size(), find(i)));     }     while (true) {       pair<int, int> cur = getMax();       if (cur.first < 2) return;       q.erase(cur);       merge(cur.second);     }   }   void dfs(int u) {     w[u] = 1;     tin[u] = cnt;     ++cnt;     for (int to : e[u]) {       int vt = find(to);       if (!w[vt])         dfs(vt);       else if (w[vt] == 1) {         ans = gcd(ans, tin[u] - tin[vt] + 1);       }     }     w[u] = 2;     --cnt;   }   void solve() {     init();     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       if (u == v) print(1);       e[u].insert(find(v));     }     compress();     for (int i = 0; i < n; ++i)       if (!w[find(i)]) dfs(find(i));     if (ans == 0) ans = n;     printf( %d n , ans);   }   int main() {     solve();     return 0;   }   