1 #include<iostream>
2 using namespace std;
3 #include<cstdio>
4 #include<algorithm>
5 #define N 10000
6 #include<stack>
7 stack <int> sta;
8 bool instack[N]={false};
9 int n,m;
10 struct Edge{
11 int u,v,last;
12 }edge[N<<1];
13 int dfn[N],low[N],father[N];
14 int t=0,sum=0,head[N]={0},topt=0,outdu[N]={0},sumout=0,ans1[N],ans2[N];
15 void add_edge(int u,int v)
16 {
17 edge[++t].v=v;
18 edge[t].u=u;
19 edge[t].last=head[u];
20 head[u]=t;
21 }
22 void input()
23 {
24 scanf("%d%d",&n,&m);
25 int u1,v1;
26 for(int i=1;i<=m;++i)
27 {
28 scanf("%d%d",&u1,&v1);
29 add_edge(u1,v1);
30 }
31 }
32 void tarjan(int k)
33 {
34 dfn[k]=low[k]=++topt;
35 sta.push(k);
36 instack[k]=true;
37 for(int l=head[k];l;l=edge[l].last)
38 {
39 if(dfn[edge[l].v]==0)
40 {
41 tarjan(edge[l].v);
42 low[k]=min(low[k],low[edge[l].v]);
43 }
44 else if(instack[edge[l].v])
45 low[k]=min(low[k],dfn[edge[l].v]);
46 }
47 if(dfn[k]==low[k])
48 {
49 int js=0;
50 int x;
51 do
52 {
53 x=sta.top();
54 sta.pop();
55 father[x]=k;
56 instack[x]=false;
57 js++;
58 }while(x!=k);
59 if(js>=2)
60 ans1[++ans1[0]]=k;
61 }
62 }
63 bool work()
64 {
65 for(int i=1;i<=m;++i)
66 {
67 int x=father[edge[i].u];
68 int y=father[edge[i].v];
69 if(x==y) continue;
70 outdu[x]++;
71 }
72 int comp;
73 for(int i=1;i<=ans1[0];++i)
74 {
75 if(outdu[ans1[i]]==0)
76 {
77 sumout++;
78 comp=ans1[i];
79 }
80 }
81 if(sumout!=1) return false;
82 for(int i=1;i<=n;++i)
83 {
84 if(father[i]==comp)
85 {
86 ans2[++ans2[0]]=i;
87 }
88 }
89 return true;
90 }
91 int main()
92 {
93 input();
94 for(int i=1;i<=n;++i)
95 {
96 if(!dfn[i])
97 tarjan(i);
98 }
99 printf("%d\n",ans1[0]);
100 if(work())
101 {
102 sort(ans2+1,ans2+ans2[0]+1);
103 for(int i=1;i<=ans2[0];++i)
104 printf("%d ",ans2[i]);
105 printf("\n");
106 }else printf("-1\n");
107 return 0;
108 }