text: a, mod - 2, mod) % mod}; } }; const int N = 100033; const int LOG = 20; const int mod = 1e9 + 7; const int inf = 1e9 + 7; int n, m; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int dep[N], vst[N]; set<pair<int, int> > s[N]; vector<int> e[N]; bool ans[N]; int anc[N], o[N]; int cur[N]; int insert[N]; bool dfs(int v) { vst[v] = true; insert[v] = true; for (int y : e[v]) { if (!vst[y]) { dep[y] = dep[v] + 1; if (!dfs(y)) return false; } else { if (insert[y] == false || dep[y] > dep[v]) { return false; } } } insert[v] = false; return true; } int _ = 0; void d1(int v) { vst[v] = true; cur[dep[v]] = v; for (int y : e[v]) { if (!vst[y]) { dep[y] = dep[v] + 1; d1(y); if (s[v].size() < s[y].size()) { swap(s[v], s[y]); } for (auto tmp : s[y]) { s[v].insert(tmp); } s[y].clear(); } else { s[v].insert(make_pair(dep[y], ++_)); } } while (!s[v].empty() && s[v].rbegin()->first >= dep[v]) { s[v].erase(*s[v].rbegin()); } anc[v] = -1; if (s[v].size() >= 2) { ans[v] = false; } else if (s[v].size() == 1) { anc[v] = cur[s[v].begin()->first]; } } void d2(int v) { vst[v] = true; if (anc[v] != -1) { ans[v] &= ans[anc[v]]; } for (int y : e[v]) { if (!vst[y]) { dep[y] = dep[v] + 1; d2(y); } } } void run() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); e[x].push_back(y); } for (int i = 1; i <= n; i++) { o[i] = i; swap(o[i], o[gene() % i + 1]); } int LIM = 100; for (int j = 1; j <= min(LIM, n); j++) { int v = o[j]; fill(insert + 1, insert + 1 + n, false); fill(vst + 1, vst + 1 + n, false); dep[v] = 1; if (dfs(v)) { fill(vst + 1, vst + 1 + n, false); fill(ans + 1, ans + 1 + n, true); d1(v); fill(vst + 1, vst + 1 + n, false); d2(v); int cnt = 0; for (int i = 1; i <= n; i++) cnt += ans[i]; for (int i = 1; i <= n; i++) s[i].clear(); if (cnt * 5 < n) { printf("-1\n"); return; } else { for (int i = 1; i <= n; i++) { if (ans[i]) { cnt--; printf("%d%c", i, cnt ?