#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_SIZE 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 100

int N,E;
vector<int> G[SIZE];
bool can_visit[SIZE][SIZE];

void bfs(int start_node){

	queue<int> Q;

	for(int i = 0; i < G[start_node].size(); i++){
		can_visit[start_node][G[start_node][i]] = true;
		Q.push(G[start_node][i]);
	}

	while(!Q.empty()){

		for(int i = 0; i < G[Q.front()].size(); i++){
			if(can_visit[start_node][G[Q.front()][i]] == false){
				can_visit[start_node][G[Q.front()][i]] = true;
				Q.push(G[Q.front()][i]);
			}
		}
		Q.pop();
	}
}

int main(){

	scanf("%d %d",&N,&E);

	int from,to;
	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)can_visit[i][k] = false;
	}

	for(int i = 0; i < N; i++)bfs(i);

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			if(can_visit[i][k] == true && can_visit[k][i] == true){
				printf("1\n");
				return 0;
			}
		}
	}

	printf("0\n");

	return 0;
}