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

const long long MaxN = 2e5 + 5;

vector<long long> a[MaxN];
long long mark[MaxN];
long long n,m;

bool dfs(long long s)
{
    stack<pair<long long,long long>> st;

    st.push({s,0});
    mark[s] = 1;

    while (!st.empty())
    {
        long long u = st.top().first;
        long long i = st.top().second;

        if (i == a[u].size())
        {
            mark[u] = 2;
            st.pop();
            continue;
        }

        long long v = a[u][i];
        st.top().second++;

        if (mark[v] == 1)
            return true;

        if (mark[v] == 0)
        {
            mark[v] = 1;
            st.push({v,0});
        }
    }

    return false;
}

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

    cin >> n >> m;

    for (long long i=1;i<=m;i++)
    {
        long long u,v;
        cin >> u >> v;
        a[u].push_back(v);
    }

    for (long long i=1;i<=n;i++)
    {
        if (mark[i]==0)
        {
            if (dfs(i))
            {
                cout << "YES";
                return 0;
            }
        }
    }

    cout << "NO";
}