#include <iostream>
#include <vector>
#include <cstdlib>

#define VMAX 100
#define EMAX 1000

using namespace std;

struct Node{
    vector<int> connect;
    char visit;
};

void dfs_visit(Node data[VMAX], Node &n);

int main(){
    int vn, en;
    int source, target;
    Node data[VMAX];
    
    cin >> vn >> en;
    
    if(!(1 <= vn && vn <= VMAX) || !(0 <= en && en <= EMAX))
        return -1;
    
    for(int i = 0;i < vn;i++)
        data[i].visit = 'W';
    
    for(int i = 0;i < en;i++){
        cin >> source >> target;
        
        if(!(0 <= source && source < vn) || !(0 <= target && target < vn))
            return -1;
        if(source == target)
            return -1;
        
        data[source].connect.push_back(target);
    }
    
    for(int i = 0; i < vn; i++)
        if(data[i].visit == 'W')
            dfs_visit(data, data[i]);
    
    cout << "0" << endl;

    return 0;
}

void dfs_visit(Node data[VMAX], Node &n){
    if(n.visit == 'G'){
        cout << "1" << endl;
        exit(0);
    }
    else if(n.visit == 'W'){
        n.visit = 'G';
        for(vector<int>::size_type i = 0;i < n.connect.size();i++)
            dfs_visit(data, data[n.connect[i]]);
        n.visit = 'B';
    }
}

