#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
const ll INF = (1ll << 60);

bool hasCycle(vvi &G) {
  ll V=G.size();
  REP(i,V) {
    vi visited(V);
    queue<ll> q; q.push(i);
    visited[i]=1;
    while(q.size()) {
      ll from=q.front();
      q.pop();
      for(ll to:G[from]) {
        if(to==i) return true;
        if(!visited[to]) {
          visited[to]=1;
          q.push(to);
        }
      }
    }
  }
  return false;
}

int main(){
  ll V,E; cin>>V>>E;
  vvi G(V);
  REP(i,E) {
    ll s,t; cin>>s>>t;
    G[s].PB(t);
  }
  if(hasCycle(G)) cout<<1<<endl;
  else cout<<0<<endl;
}