#include <bits/stdc++.h>
using namespace std;
int gra[1002][1005];
int vis[1002];
int n,m;
void dfs(int x)
{
vis[x] = 1;
for(int i = 1; i <= n ; i ++)
{
if(gra[x][i] == 1 && !vis[i])
{
dfs(i);
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(gra,0,sizeof(gra));
memset(vis,0,sizeof(vis));
int u,v;
for(int i = 0; i < m; i ++)
{
scanf("%d %d",&u,&v);
gra[u][v] = 1;
}
dfs(n);
if(vis[1] == 1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}