// AOJ GRL_4_A Path/Cycle - Cycle Detection for a Directed Graph
// 2018.4.26 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_V 102
int V;   // 頂点数
int to[MAX_V][MAX_V], hi[MAX_V];
int q[MAX_V], top, end;
int count[MAX_V];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int topological_sort()
{
    int i, j, k, f;

//  for (i = 0; i < V; i++) for (j = 0; j < hi[i]; j++) count[to[i][j]]++;

    top = end = 0;
	f = 0;
    for (i = 0; i < V; i++) if (!count[i]) q[end++] = i;
    while (top < end) {
		i = q[top++];
        f++;
        for (j = 0; j < hi[i]; j++) {
            k = to[i][j];
            if (--count[k] == 0) q[end++] = k;
        }
    }
	return f == V;
}

int main()
{
	int E, s, t;

	V = in(), E = in();
	while (E--) {
		s = in(), t = in();
		to[s][hi[s]++] = t;
		count[t]++;
	}

	puts(topological_sort()? "0": "1");
	return 0;
}
