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

#define DIM 100007

typedef long long ll;
typedef long double ld;


ll n, used[DIM], res, c, m, v1, v2;
vector<ll> v[DIM];
bool cc;

void dfs(ll x){
    if(used[x]==2) return;
    if(used[x] == 1){
        used[x] = 2;
        cc=true;
        return;
    }
    used[x] = 1;
    for(int i=0; i<v[x].size(); i++){
        ll to = v[x][i];
        dfs(to);
    }
    
}

int main(){
    
    cin>>n>>m;
    cc = false;
    for(int i=1;i<=m;i++){
        cin>>v1>>v2;
        v[v1].push_back(v2);
        
    }
    
    dfs(1);
    
    res = 1;
    if(cc==false) res = 0;
    
    for(int i=1;i<=n;i++){
        if(used[i]==0) res = 0;
    }
    
    cout<<"NO"<<endl;
    
    return 0;
}
