#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

const int MAX_V = 100;
std::vector<int> G[MAX_V];
int used[MAX_V];

int main(){
    int V, E;
    std::cin >> V >> E;
    
    REP(i, E){
        int u, v;
        std::cin >> u >> v;
        G[u].push_back(v);
    }

    std::queue<int> q;
    q.push(0);
    
    bool f = false;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        used[v] = 1;

        REP(i, G[v].size()){
            int u = G[v][i];
            if(!used[u]){
                q.push(u);
            }else{
                f = true;
            }
        }
    }

    if(f){puts("1");}
    else{puts("0");}
}