#include <bits/stdc++.h>
using namespace std;
const long long N = 100100;
vector <long long> e [N];
long long n;
bool ansex = true;

void dfs (long long v,map <long long,bool> vis,vector <int> path)
{
    vis[v] = 1;
    path.push_back(v);
    if (path.size() > n)
    {
        cout << "NO";
    }
    for (long long t:e[v])
    {
        if (vis[t] == 1)
        {
            if (t == 1)
            {
                bool ans = true;
                for (long long i = 1 ; i <= n ; i++)
                {
                    if (vis[i] == 0)
                    {
                        ans = false;
                    }
                }
                // if (ans)
                // {
                //     ansex = false;
                //     cout << "YES" << '\n';
                //     for (int p:path)
                //     {
                //         cout << p << " ";
                //     }
                //     cout << 1;
                // }
            }
            else
            {
                continue;
            }
        }
        else
        {
            dfs(t,vis,path);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	long long m,a,b;
    cin >> n >> m;
    for (long long i = 1 ; i <= m ; i ++)
    {
        cin >> a >> b;
        e[a].push_back(b);
    }
    dfs(1,{},{});
    // if (ansex)
    // {
        cout << "NO";
    // }
}
