#include<iostream>
#include<cstdio>
#define N 1000000
using namespace std;
struct edge_node
{
int to,next;
}e[N],d[N];
//int chudu[100];
int head[N],h[N];
bool instack [N];
int stack [N];
int dfn[N], low[N];
int size[N],belong[N];
int cnt,index,top,scc;
int n,m,u,v;
void tarjan(int u)
{
dfn[u] = low[u] = ++index;
instack[u] = true;
stack[++top] = u;
for (int i = head[u];i;i = e[i].next)
{
int v = e[i].to;
if (instack[v])
{
low[u] = min(low[u],dfn[v]);
}
if (!dfn[v])
{
tarjan(v);
low[u] = min(low[u],low[v]);
}
}
if (low[u] == dfn[u])
{
scc++;
int v = 0;
for (;u!=v;)
{
v=stack[top--];
instack[v] = false;
belong[v] = scc;
size[scc]++;
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
e[++cnt].to = v;
e[cnt].next = head[u];
head[u] = cnt;
}
for (int i=1;i<=n;i++)
if (!dfn[i])
tarjan(i);
int ans1 = 0;
for (int i=1;i<=scc;i++)
if (size[i]!=1) ans1++;
printf("%d\n",ans1);
cnt = 0;
for (int i=1;i<=n;i++)
{
for (int j = head[i];j;j = e[j].next)
{
int v = e[j].to;
if (belong[i] != belong[v])
{
d[++cnt].to = belong[v];
d[cnt].next = h[belong[i]];
h[belong[i]] = cnt;
// chudu[belong[i]] ++;
}
}
}
// printf("size:");
// for (int i=1;i<=scc;i++) printf("%d ",size[i]);printf("\n");
// printf("chudu:");
// for (int i=1;i<=scc;i++) printf("%d ",chudu[i]);
int pd =0;
for (int i=1;i<=scc;i++)
{
if (!h[i] && size[i]!=1)
{
if (pd!=0)
{
pd = 0;
break;
}
pd = i;
}
}
if (pd)
{
for (int j=1;j<=n;j++)
if (belong[j] == pd)
printf("%d ",j);
}
else printf("-1");
}