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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

const int max_v=100;
vector<int> graph[max_v],topo_ord;
int state[max_v]; //0:まだ訪れていない、1:途中、2:探索済み

bool topo_dfs(int v){
    if(state[v]==1) return false;
    if(state[v]==2) return true;
    
    state[v]=1;
    for(auto u:graph[v]) if(!topo_dfs(u)) return false;
    state[v]=2;
    
    topo_ord.push_back(v);
    return true;
}

void solve(){
    int v,e;
    cin >> v >> e;
    rep(i,0,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
    }
    
    rep(i,0,v){
        if(!topo_dfs(i)){
            cout << 1 << endl;
            return;
        }
    }
    cout << 0 << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}