#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)

signed main(){

  int v,e;
  cin>>v>>e;
  vector<vector<int>> adj(v);
  rep(i,e){
    int s,t;cin>>s>>t;
    adj[s].emplace_back(t);
  }

  auto bfs = [&](int s){
    queue<int> que;
    vector<int> visited(v);
    visited[s] = 1;
    for(auto nv:adj[s])que.emplace(nv);
    while(!que.empty()){
      int v = que.front();
      que.pop();
      if(v==s){
        cout<< 1 <<endl;
        exit(0);
      }
      if(visited[v])continue;
      visited[v] = 1;
      for(auto nv:adj[v]){
        que.emplace(nv);
      }
    }
  };

  rep(i,v){
    bfs(i);
  }
  cout<< 0 <<endl;

}
