1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
#define maxn 1000100
int a, b, n, m;
bool cand[maxn];
vector <int> v[maxn];
int stan[maxn];

bool czy = false;
int blocked;
void dfs(int x) {
	if (x == blocked) return;
	stan[x] = 1;
	for (ui i=0; i<v[x].size(); ++i)
	   if (stan[v[x][i]] == 1) czy = true;
	   else if (stan[v[x][i]] == 0) dfs(v[x][i]);
	stan[x] = 2;
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i=1; i<=m; ++i) 
	{
		scanf("%d%d", &a, &b);
		v[a].pb(b);
	}
	
	for (int i=1; i<=n; ++i) v[0].pb(i);	
	blocked = -1;
	dfs(0);

	if (czy == false) OUT("NIE");
	vector <int> wyn;
	wyn.clear();
	for (int i=1; i<=n; ++i)
	{
		fill(stan, stan + n + 5, 0);
		blocked = i;
		czy = false;
		dfs(0);
		if (czy == false) wyn.pb(i);
	}
	 printf("%d\n", (int)wyn.size());
	 for (ui i=0; i<wyn.size(); ++i) printf("%d ", wyn[i]);
}