#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int d[111][111],n,m,a,b;
int main(){
	r(i,111)r(j,111)d[i][j]=(i==j?0:1e5);
	cin>>n>>m;
	while(m--){
		cin>>a>>b;
		d[a][b] = -1;
	}
	r(k,n)r(i,n)r(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	r(i,n){
		if(d[i][i]<0){
			cout<<1<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
}
