#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;
int V, E;
std::vector<int> G[MAX_V];
int used[MAX_V];
int isConnected[MAX_V][MAX_V];

bool bfs(int s){
    std::fill(used, used+V, 0);
    
    std::queue<int> q;
    q.push(s);
    used[s] = 1;
    
    while(!q.empty()){
        int u = q.front(); q.pop();

        REP(i, G[u].size()){
            int v = G[u][i];
            if(!used[v]){
                if(isConnected[v][s]){return true;}
                q.push(v);
                used[v] = 1;
                isConnected[s][v] = 1;
            }
        }
    }

    return false;
}

int main(){
    std::cin >> V >> E;

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

    bool f = false;
    REP(v, V){
        f |= bfs(v);
    }

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