/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 100005
#define nm 200005
#define pi 3.1415926535897931
using namespace std;
const ll inf=100000000000000005;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
struct edge{int t;edge*next;}e[nm],*h[NM],*o=e;
void add(int x,int y){o->t=y;o->next=h[x];h[x]=o++;}
int n,m,_x,_y,b[NM],c[NM],d[NM],suc[NM],low[NM],cnt,ans,tot;
stack<int>s;
void dfs(int x){
d[x]=low[x]=++tot;s.push(x);
link(x)if(!d[j->t]){
dfs(j->t);low[x]=min(low[x],low[j->t]);
}else if(!suc[j->t])low[x]=min(low[x],low[j->t]);
if(low[x]==d[x]){
c[++cnt]=x;int t;
do{
t=s.top();s.pop();
suc[t]=cnt;c[cnt]=min(c[cnt],t);
}while(x!=t);
}
}
int main(){
n=read();m=read();
inc(i,1,m){_x=read();_y=read();add(_x,_y);}
inc(i,1,n)if(!d[i])dfs(i);
inc(i,1,n)link(i)if(suc[i]!=suc[j->t])b[suc[j->t]]++;
inc(i,1,cnt)if(!b[i])d[++ans]=c[i];
printf("%d\n",ans);
sort(d+1,d+1+ans);
inc(i,1,ans-1)printf("%d ",d[i]);
return 0*printf("%d\n",d[ans]);
}