#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define p_queue priority_queue
#define DBG printf("this is a input\n")
#define fi first
#define se second
#define mk(a, b) make_pair(a,b)
#define pb(a) push_back(a)
#define CLOSE ios::sync_with_stdio(0); cin.tie(0)
const int N = 5005;
int n , m;
vector <int> edge[N];
vector <int> scc[N];
int times , tot;
int dfn[N] , low[N], vis[N], co[N], st[N], type = 0;
int in[N], Index, lin[N];
void tarjan(int u)
{
dfn[u] = low[u] = ++ times;
st[++ tot] = u;
vis[u] = 1;
for(int i = 0 ; i < edge[u].size() ; i ++)
{
int t = edge[u][i];
if(!dfn[t])
{
tarjan(t);
low[u] = min(low[u],low[t]);
}
else if(vis[t])
low[u] = min(low[u],dfn[t]);
}
if(low[u] == dfn[u])
{
type ++;
do{
scc[type].pb(st[tot]);
vis[st[tot]] = 0;
tot --;
}while(u != st[tot+1]);
}
return ;
}
queue <int> q;
bool top()
{
while(!q.empty())
q.pop();
for (int i = 1 ; i <= n ; i ++)
lin[i] = in[i];
int px = 0;
for (auto it : scc[Index])
if(in[it] == 0)
q.push(it);
px = q.size();
if(q.size() == 0)
return false;
else
{
while(!q.empty())
{
int u = q.front();
q.pop();
for (auto v : edge[u])
{
if(co[v])
{
lin[v] --;
if(lin[v] == 0)
{
q.push(v);
px += 1;
}
}
}
}
if(px == scc[Index].size())
return true;
return false;
}
}
int main(void)
{
CLOSE;
cin >> n >> m;
for (int i = 1 ; i <= m ; i ++)
{
int u , v;
cin >> u >> v;
edge[u].pb(v);
}
for (int i = 1 ; i <= n ; i ++)
if(!dfn[i])
tarjan(i);
int cnt = 0;
for (int i = 1 ; i <= type ; i ++)
{
if(scc[i].size() >= 2) {
Index = i;
for (auto it : scc[i])
co[it] = 1;
cnt++;
}
}
if(cnt == 0)
{
cout << "YES" <<endl;
return 0;
}
if(cnt == 1)
{
for (int i = 1 ; i <= n ;i ++)
for (int j = 0 ; j < edge[i].size() ; j ++)
{
int v = edge[i][j];
if(co[i] && co[v])
in[v] ++;
}
int flag = 1;
for (int i = 1 ; i <= n ;i ++) {
if (co[i]) {
for (int j = 0; j < edge[i].size(); j++) {
int v = edge[i][j];
if (co[v]) {
in[v]--;
if (top()) {
flag = 0;
break;
}
in[v]++;
}
}
if (!flag)
break;
}
}
if(flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
else
cout << "NO" << endl;
}