#include <stdio.h>
#include <stdbool.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int color[100];
int a[100][100] ;
int k;
int check=0;
int v2;
bool cycle = false;

void CLOSE(int x){
int i;
color[x] = GRAY;
for(int i = 0; i < v2; i++){
		if(a[x][i] == 0) continue;
		if(color[i] == GRAY){
				cycle = true;
				return;
		}
		if(color[i] == WHITE) CLOSE(i);
}
color[x] = BLACK;
}

int main(){

 int e,s,t,i,j;
		scanf("%d %d", &v2,&e);
		for(i=0; i<v2;i++){
			color[i] = WHITE;
			for(j=0; j<v2;j++){
				a[i][j]=0;
			}
		}
	for(i=0; i<e;i++){
		scanf("%d %d", &s,&t);
		a[s][t] = 1;
	}
	for( i = 0; i < s; i++){
			if(color[i] == WHITE) CLOSE(i);
			if(cycle){
					printf("1\n");
					return 0;
				}

		}
		printf("0\n");

				return 0;
}

