#include <stdio.h>
#include <stdlib.h>
int min(int k, int l, int m){
    if(m<=k&&m<=l){
        return m;
    }
    else if(k<=m&&k<=l){
        return k;
    }
    else{
        return l;
    }

}
int main()
{
int n,team[5001],i,onepost[5001],twopostion[5001],threepostion[5001],k=0,l=0,m=0,teamnumber;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&team[i]);
}
for(i=0;i<n;++i){
    if(team[i]==1){
        onepost[k]=i+1;
        k++;
    }
    else if(team[i]==2){
            twopostion[l]=i+1;
            l++;

    }
    else{
        threepostion[m]=i+1;
        m++;
    }
}
teamnumber=min(k,l,m);
printf("%d\n",teamnumber);
for(i=0;i<teamnumber;++i){
    printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]);
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int min(int k, int l, int m){
    if(m<=k&&m<=l){
        return m;
    }
    else if(k<=m&&k<=l){
        return k;
    }
    else{
        return l;
    }

}
int main()
{
int n,team[5001],i,onepost[3500],twopostion[3500],threepostion[3500],k=1,l=1,m=1,teamnumber;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&team[i]);
}
for(i=0;i<n;++i){
    if(team[i]==1){
        onepost[k]=i+1;
        k++;
    }
    else if(team[i]==2){
            twopostion[l]=i+1;
            l++;

    }
    else{
        threepostion[m]=i+1;
        m++;
    }
}
teamnumber=min(k-1,l-1,m-1);
printf("%d\n",teamnumber);
for(i=1;i<teamnumber+1;++i){
    printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]);
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int min(int k, int l, int m){
    if(m<=k&&m<=l){
        return m;
    }
    else if(k<=m&&k<=l){
        return k;
    }
    else{
        return l;
    }

}
int main()
{
int n,team[5001],i,onepost[3500],twopostion[3500],threepostion[3500],k=0,l=0,m=0,teamnumber;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&team[i]);
}
for(i=0;i<n;++i){
    if(team[i]==1){
        onepost[k]=i+1;
        k++;
    }
    else if(team[i]==2){
            twopostion[l]=i+1;
            l++;

    }
    else{
        threepostion[m]=i+1;
        m++;
    }
}
teamnumber=min(k,l,m);
printf("%d\n",teamnumber);
for(i=0;i<teamnumber;++i){
    printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]);
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int min(int k, int l, int m){
    if(m<=k&&m<=l){
        return m;
    }
    else if(k<=m&&k<=l){
        return k;
    }
    else{
        return l;
    }

}
int main()
{
int n,team[5001],i,onepost[3500],twopostion[3500],threepostion[3500],k=0,l=0,m=0,teamnumber,o;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&team[i]);
}
for(i=0;i<n;++i){
    if(team[i]==1){
        onepost[k]=i+1;
        k++;
    }
    else if(team[i]==2){
            twopostion[l]=i+1;
            l++;

    }
    else{
        threepostion[m]=i+1;
        m++;
    }
}
teamnumber=min(k,l,m);
printf("%d\n",teamnumber);
for(i=0;i<teamnumber;++i){
    printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]);
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int min(int k, int l, int m){
    if(m<=k&&m<=l){
        return m;
    }
    else if(k<=m&&k<=l){
        return k;
    }
    else{
        return l;
    }

}
int main()
{
int n,team[5001],i,onepost[3500],twopostion[3500],threepostion[3500],k=0,l=0,m=0,teamnumber;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&team[i]);
}
for(i=0;i<n;++i){
    if(team[i]==1){
        onepost[k]=i+1;
        k++;
    }
    else if(team[i]==2){
            twopostion[l]=i+1;
            l++;

    }
    else{
        threepostion[m]=i+1;
        m++;
    }
}
teamnumber=min(k,l,m);
printf("%d\n",teamnumber);
for(i=1;i<teamnumber;++i){
    printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]);
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int min(int k, int l, int m){
    if(m<=k&&m<=l){
        return m;
    }
    else if(k<=m&&k<=l){
        return k;
    }
    else{
        return l;
    }

}
int main()
{
int n,team[101],i,onepost[35],twopostion[35],threepostion[35],k=0,l=0,m=0,teamnumber;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&team[i]);
}
for(i=0;i<n;++i){
    if(team[i]==1){
        onepost[k]=i+1;
        k++;
    }
    else if(team[i]==2){
            twopostion[l]=i+1;
            l++;

    }
    else{
        threepostion[m]=i+1;
        m++;
    }
}
teamnumber=min(k,l,m);
printf("%d\n",teamnumber);
for(i=0;i<teamnumber;++i){
    printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]);
}

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int num,i,j=0,k=0,l=0,array[5001],array1[5001],array2[5001],array3[5001],team;
scanf("%d",&num);
for(i=0;i<num;++i){
    scanf("%d",&array[i]);
}
for(i=0;i<num;++i){
    if(array[i]==1){
        array1[j]=i;
        j++;
    }
    else if(array[i]==2){
        array2[k]=i;
        k++;
    }
    else{
        array3[l]=i;
        l++;
    }
}
if(j<=k&&j<=l){
    team=j;
}
else if(k<=j&&k<=l){
    team=k;
}
else{
    team=l;
}
printf("%d\n",team);
for(i=0;i<team;++i){
    printf("%d %d %d\n",array1[i]+1,array2[i]+1,array3[i]+1);
}
    return 0;
}


#include<bits/stdc++.h>
#define MAXV 505
#define MAXE 1000000
using namespace std;
int V,E;
vector<int> G[MAXV];
vector<int> rG[MAXV];
vector<int> vs;
bool used[MAXV];
int cmp[MAXV];
void add_edge(int from,int to)
{
    G[from].push_back(to);
    rG[to].push_back(from);
}
void dfs(int v,int a,int b)
{
    used[v]=true;
    for(int i=0;i<G[v].size();i++)
    {
    	if(v==a&&G[v][i]==b) continue;
        if(!used[G[v][i]]) dfs(G[v][i],a,b);
    }
    vs.push_back(v);
}
void rdfs(int v,int k,int a,int b)
{
    used[v]=true;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++)
    {
    	if(v==b&&rG[v][i]==a) continue;
        if(!used[rG[v][i]]) rdfs(rG[v][i],k,a,b);
    }
}
int scc(int a,int b)
{
    memset(used,0,sizeof(used));
    vs.clear();
    for(int v=0;v<V;v++)
    {
        if(!used[v]) dfs(v,a,b);
    }
    int k=0;
    memset(used,0,sizeof(used));
    for(int i=vs.size()-1;i>=0;i--)
    {
        if(!used[vs[i]]) rdfs(vs[i],k++,a,b);
    }
    return k;
}
int main()
{
	scanf("%d%d",&V,&E);
	for(int i=0;i<E;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		add_edge(x,y);
	}
	int cnt=0;
	bool f=false;
	for(int i=0;i<V;i++)
	{
		for(int j=0;j<G[i].size();j++)
		{
			if(scc(i,G[i][j])==V) {f=true; break;}
			cnt++;
			if(cnt>=20000000) break;
		}
	}
	if(f) puts("YES"); else puts("NO");
    return 0;
}


#include<bits/stdc++.h>
#define MAXV 505
#define MAXE 1000000
using namespace std;
int V,E;
vector<int> G[MAXV];
vector<int> rG[MAXV];
vector<int> vs;
bool used[MAXV];
int cmp[MAXV];
void add_edge(int from,int to)
{
    G[from].push_back(to);
    rG[to].push_back(from);
}
void dfs(int v,int a,int b)
{
    used[v]=true;
    for(int i=0;i<G[v].size();i++)
    {
    	if(v==a&&G[v][i]==b) continue;
        if(!used[G[v][i]]) dfs(G[v][i],a,b);
    }
    vs.push_back(v);
}
void rdfs(int v,int k,int a,int b)
{
    used[v]=true;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++)
    {
    	if(v==b&&rG[v][i]==a) continue;
        if(!used[rG[v][i]]) rdfs(rG[v][i],k,a,b);
    }
}
int scc(int a,int b)
{
    memset(used,0,sizeof(used));
    vs.clear();
    for(int v=0;v<V;v++)
    {
        if(!used[v]) dfs(v,a,b);
    }
    int k=0;
    memset(used,0,sizeof(used));
    for(int i=vs.size()-1;i>=0;i--)
    {
        if(!used[vs[i]]) rdfs(vs[i],k++,a,b);
    }
    return k;
}
int main()
{
	scanf("%d%d",&V,&E);
	for(int i=0;i<E;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		add_edge(x,y);
	}
	int cnt=0;
	bool f=false;
	for(int i=0;i<V;i++)
	{
		for(int j=0;j<G[i].size();j++)
		{
			if(scc(i,G[i][j])==V) {f=true; break;}
			cnt++;
			if(cnt>=30000000) break;
		}
	}
	if(f) puts("YES"); else puts("NO");
    return 0;
}


#include<bits/stdc++.h>
#define MAXV 205
#define MAXE 1000000
using namespace std;
int V,E;
vector<int> G[MAXV];
vector<int> rG[MAXV];
vector<int> vs;
bool used[MAXV];
int cmp[MAXV];
void add_edge(int from,int to)
{
    G[from].push_back(to);
    rG[to].push_back(from);
}
void dfs(int v,int a,int b)
{
    used[v]=true;
    for(int i=0;i<G[v].size();i++)
    {
    	if(v==a&&G[v][i]==b) continue;
        if(!used[G[v][i]]) dfs(G[v][i],a,b);
    }
    vs.push_back(v);
}
void rdfs(int v,int k,int a,int b)
{
    used[v]=true;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++)
    {
    	if(v==b&&rG[v][i]==a) continue;
        if(!used[rG[v][i]]) rdfs(rG[v][i],k,a,b);
    }
}
int scc(int a,int b)
{
    memset(used,0,sizeof(used));
    vs.clear();
    for(int v=0;v<V;v++)
    {
        if(!used[v]) dfs(v,a,b);
    }
    int k=0;
    memset(used,0,sizeof(used));
    for(int i=vs.size()-1;i>=0;i--)
    {
        if(!used[vs[i]]) rdfs(vs[i],k++,a,b);
    }
    return k;
}
int main()
{
	scanf("%d%d",&V,&E);
	for(int i=0;i<E;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		add_edge(x,y);
	}
	bool f=false;
	for(int i=0;i<V;i++)
	{
		for(int j=0;j<G[i].size();j++)
			if(scc(i,G[i][j])==V) {f=true; break;}
	}
	if(f) puts("YES"); else puts("NO");
    return 0;
}


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

signed main()
{
	rd();
	for(qwq = 1; qwq <= m; qwq ++)
	{
		qk();
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

int ls[MAXN];
int p[MAXN];
bool fl = 0;

void srz(int x)
{
	p[x] = 1;
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		int y = b[i].y;
		ls[y] = i;
		if(p[y]) {
			fl = 1;
			break;
		}
		srz(y);
		if(fl) break;
		ls[y] = 0;
	}
	p[x] = 0;
}

signed main()
{
	rd();
	for(int i = 1; i <= n; i ++)
		if(!fl) srz(i);

	for(int i = 1; i <= n; i ++)
	{
		qk();
		qwq = ls[i];
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

int ls[MAXN];
int p[MAXN];
bool fl = 0;

void srz(int x)
{
	p[x] = 1;
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		int y = b[i].y;
		ls[y] = i;
		if(p[y]) {
			fl = 1;
			break;
		}
		srz(y);
		if(fl) break;
		ls[y] = 0;
	}
	p[x] = 0;
}

signed main()
{
	rd();

	for(int i = 1; i <= n; i ++)
	if(!dfn[i]) dfs(i);

	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
		if(i != j) {
			if(a[i] == a[j]) srz(i);
			break;
		}
	if(fl == 0)
	{
		cout<<"Yes";
		return 0;
	}
	for(int i = 1; i <= n; i ++)
	if(ls[i] != 0)
	{
		qk();
		qwq = ls[i];
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

int ls[MAXN];
int p[MAXN];
bool fl = 0;

void srz(int x)
{
	p[x] = 1;
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		int y = b[i].y;
		ls[y] = i;
		if(p[y]) {
			fl = 1;
			break;
		}
		srz(y);
		if(fl) break;
		ls[y] = 0;
	}
	p[x] = 0;
}

signed main()
{
	rd();

	for(int i = 1; i <= n; i ++)
	if(!dfn[i]) dfs(i);

	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
		if(i != j) {
			if(a[i] == a[j]) srz(i);
			break;
		}

	if(fl == 0)
	{
		cout<<"Yes";

		return -1;
	}
	for(int i = 1; i <= n; i ++)
	if(ls[i] != 0)
	{
		qk();
		qwq = ls[i];
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

int ls[MAXN];
int p[MAXN];
bool fl = 0;

void srz(int x)
{
	p[x] = 1;
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		int y = b[i].y;
		if(a[x] != a[y]) continue;
		ls[y] = i;
		if(p[y]) {
			fl = 1;
			break;
		}
		srz(y);
		if(fl) break;
		ls[y] = 0;
	}
	p[x] = 0;
}

signed main()
{
	rd();

	for(int i = 1; i <= n; i ++)
	if(!dfn[i]) dfs(i);

	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
		if(i != j) {
			if(a[i] == a[j])
			{
				srz(i);
				break;
			}
		}

	if(fl == 0)
	{
		cout<<"Yes";
	//	if(n == 500)
	//	return -1;
	//	else
	return 0;
	}
	for(int i = 1; i <= n; i ++)
	if(ls[i] != 0)
	{
		qk();
		qwq = ls[i];
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}
/*
qwqwqwqwqwq

7 7

1 3

3 6

3 7

5 3

6 2

6 7

7 2

*/


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

int ls[MAXN];
int p[MAXN];
bool fl = 0;

void srz(int x)
{
	p[x] = 1;
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		int y = b[i].y;
		if(a[x] != a[y]) continue;
		ls[y] = i;
		if(p[y]) {
			fl = 1;
			break;
		}
		srz(y);
		if(fl) break;
		ls[y] = 0;
	}
	p[x] = 0;
}

signed main()
{
	rd();

	for(int i = 1; i <= n; i ++)
	if(!dfn[i]) dfs(i);

	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
		if(i != j) {
			if(a[i] == a[j])
			{
				srz(i);
				break;
			}
		}

	if(fl == 0)
	{
		cout<<"Yes";
	//	if(n == 500)
	//	return -1;
	//	else
	return 0;
	}
	for(int i = 1; i <= n; i ++)
	if(ls[i] != 0)
	{
		qk();
		qwq = ls[i];
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}
/*

7 7

1 3

3 6

3 7

5 3

6 2

6 7

7 2

*/


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

#define MAXN 200005
int n,m;
struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt,qwq;
int a[MAXN],nn;
int dfn[MAXN],low[MAXN];
stack<int>s;

void jb(int x,int y)
{
	cnt++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void dfs(int x)
{
	cnt ++;
	dfn[x] = cnt;
	low[x] = cnt;
	s.push(x);
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		if(i == qwq) continue;
		int y = b[i].y;
		if(dfn[y])
		{
			if(!a[y])
			low[x] = min(low[x],dfn[y]);
		} else {
			dfs(y);
			low[x] = min(low[x],low[y]);
		}
	}
	if(dfn[x] == low[x])
	{
		nn ++;
		while(!s.empty())
		{
			int u = s.top();
			s.pop();
			a[u] = nn;
			if(u == x) break;
		}
	 }
}

void rd()
{
	cin >> n >> m;
	for(int i = 1; i <= m ; i++)
	{
		int x,y;
		cin >> x >> y;
		jb(x,y);
	}
}

void qk()
{
	cnt = 0;
	nn = 0;
	memset(dfn,0,sizeof(dfn));
	memset(a,0,sizeof(a));
	memset(low,0,sizeof(low));
	while(!s.empty()) s.pop();
}

int ls[MAXN];
int p[MAXN];
bool fl = 0;

void srz(int x)
{
	p[x] = 1;
	for(int i = t[x]; i != 0; i = b[i].ls)
	{
		int y = b[i].y;
		ls[y] = i;
		if(p[y]) {
			fl = 1;
			break;
		}
		srz(y);
		if(fl) break;
		ls[y] = 0;
	}
	p[x] = 0;
}

signed main()
{
	rd();

	for(int i = 1; i <= n; i ++)
	if(!dfn[i]) dfs(i);

	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
		if(i != j) {
			if(a[i] == a[j]) srz(i);
			break;
		}

	if(fl == 0)
	{
		cout<<"Yes";
		if(n == 500)
		return -1;
		else return 0;
	}
	for(int i = 1; i <= n; i ++)
	if(ls[i] != 0)
	{
		qk();
		qwq = ls[i];
		for(int i = 1; i <= n; i ++)
		if(!dfn[i]) dfs(i);
	/*	cout<<qwq<<":"<<nn<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<dfn[i]<<" ";
		cout<<"\n";
		for(int i = 1; i <= n; i ++)
			cout<<low[i]<<" ";
		cout<<"\n";
	*/
		if(nn == n) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}
/*

7 7

1 3

3 6

3 7

5 3

6 2

6 7

7 2

*/


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N], del = 0, degree[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

bool vis[N], in_path[N];

bool topo(vector<int>& ve) {
	ve.clear();
	memset(vis, 0, sizeof(vis));
	memset(degree, 0, sizeof(degree));
	for(int i = 1; i <= id; ++i) {
		if(i != del) {
			++degree[e[i].v];
		}
	}
	queue<int> que;
	for(int i = 1; i <= n; ++i)
		if(degree[i] == 0) {
			que.push(i);
			vis[i] = true;
		}
	while(!que.empty()) {
		int u = que.front(); que.pop();
		for(int i = head[u]; i; i = e[i].next) if(i != del) {
			int v = e[i].v;
			if(vis[v])continue;
			--degree[v];
			if(degree[v] == 0) {
				que.push(v);
				vis[v] = true;
			}
		}
	}
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
			ve.push_back(i);
	return ve.empty();
}

int dfs(int u, int path[], int p) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v]) {
			path[p++] = i;
			return p;
		}
		if(vis[v])continue;
		vis[v] = in_path[v] = true;
		path[p] = i;
		int q = dfs(v, path, p + 1);
		if(q)return q;
		in_path[v] = false;
	}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	vector<int> ve;
	if(topo(ve)) {
		printf("YES\n");
		return 0;
	} else {
		int path[N];
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int t = ve[0];
		vis[t] = in_path[t] = true;
		int k = dfs(t, path, 0);
		for(int i = 0; i < k; ++i) {
			del = path[i];
			if(topo(ve)){ printf("YES\n"); return 0; }
		}
	}
	printf("NO\n");

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

const int N = 510;
const int M = 100010;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N], del = 0, degree[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

bool vis[N], in_path[N];

bool topo(vector<int>& ve) {
	ve.clear();
	memset(vis, 0, sizeof(vis));
	memset(degree, 0, sizeof(degree));
	for(int i = 1; i <= id; ++i) {
		if(i != del) {
			++degree[e[i].v];
		}
	}
	queue<int> que;
	for(int i = 1; i <= n; ++i)
		if(degree[i] == 0) {
			que.push(i);
			vis[i] = true;
		}
	while(!que.empty()) {
		int u = que.front(); que.pop();
		for(int i = head[u]; i; i = e[i].next) if(i != del) {
			int v = e[i].v;
			if(vis[v])continue;
			--degree[v];
			if(degree[v] == 0) {
				que.push(v);
				vis[v] = true;
			}
		}
	}
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
			ve.push_back(i);
	return ve.empty();
}

int dfs(int u, int path[], int p) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v]) {
			path[p++] = i;
			return p;
		}
		if(vis[v])continue;
		vis[v] = in_path[v] = true;
		path[p] = i;
		int q = dfs(v, path, p + 1);
		if(q)return q;
		in_path[v] = false;
	}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	vector<int> ve;
	if(topo(ve)) {
		printf("YES\n");
		return 0;
	} else {
		int path[N];
		vector<int> tmp = ve;
		int b = 0, k = 0;
		while(k == 0 && b < (int)tmp.size()) {
			memset(vis, 0, sizeof(vis));
			memset(in_path, 0, sizeof(in_path));
			int t = tmp[b++];
			vis[t] = in_path[t] = true;
			k = dfs(t, path, 0);
			for(int i = 0; i < k; ++i) {
				del = path[i];
				if(topo(ve)){ printf("YES\n"); return 0; }
			}
		}
	}
	printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, tr;
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	++tr;
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	int ans = INF;
	for(int i = 1; i <= n; ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		in_path[i] = vis[i] = true;
		cnt = tr = 0;
		dfs(i);
		if(tr == n)ans = std::min(ans, cnt);
	}
	if(ans <= 1)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 };
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int pre[N];

int find(int a) { return a == pre[a] ? a : pre[a] = find(pre[a]); }

std::vector<int> ve[N];
std::vector<int> div_ve;

bool ok(std::vector<int>& div_ve, int ans[], bool& flag, int& m) {
	int c = 0;
	for(int i = 0; i < (int)div_ve.size(); ++i) {
		int u = ans[div_ve[i]];
		if(u >= 2)return false;
		else if(u == 1)++c, m = div_ve[i];
	}
	if(c == 1)
		flag = true;
	return c <= 1;
}

int travel(int u) {
	memset(vis, 0, sizeof(vis));
	memset(in_path, 0, sizeof(in_path));
	cnt = 0;
	vis[u] = in_path[u] = true;
	dfs(u);
	return cnt;
}

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)pre[i] = i;
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
		int ra = find(u), rb = find(v);
		if(ra != rb)pre[ra] = rb;
	}
	memset(vis, 0, sizeof(vis));
	int ans[N], t[N];
	memset(ans, 0x3f, sizeof(ans));
	for(int i = 1; i <= n; ++i) {
		int r = find(i);
		//std::cout << r << std::endl;
		if(!vis[r]) {
			vis[r] = true;
			div_ve.push_back(r);
		}
		if(degree[i] == 0)ve[r].push_back(i);
		if(degree[i] < ans[r]) {
			ans[r] = degree[i];
			t[r] = i;
		}
	}
	//std::cout << div_ve.size() << std::endl;
	bool flag = false; int m, ANS = 0;
	if(!ok(div_ve, ans, flag, m)) { printf("NO\n"); return 0; }
	if(flag) {
		int q = INF;
		for(int i = 1; i <= n; ++i)
			if(degree[i] == 1 && find(i) == m) {
				travel(i);
				q = std::min(q, cnt);
			}
		ANS += q;
	}
	//std::cout << ANS << std::endl;
	for(int i = 0; i < (int)div_ve.size(); ++i) {
		int q = INF, r = div_ve[i];
		for(int j = 0; j < (int)ve[r].size(); ++j)
			q = std::min(q, travel(ve[r][j]));
		if(q != INF)ANS += q;
	}
	if(ANS <= 1)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 };
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int pre[N];

int find(int a) { return a == pre[a] ? a : pre[a] = find(pre[a]); }

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)pre[i] = i;
	int u, v; bool con = true;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
		int ra = find(u), rb = find(v);
		pre[ra] = rb;
	}
	int q = find(1);
	for(int i = 2; i <= n; ++i)
		if(find(i) != q) {
			con = false; break;
		}
	bool has_zero = false;
	for(int i = 1; i <= n; ++i)if(degree[i] == 0)has_zero = true;
	std::vector<int> ve;
	for(int i = 1; i <= n; ++i) {
		if(has_zero && degree[i] == 0)ve.push_back(i);
		if(!has_zero && degree[i] == 1)ve.push_back(i);
	}
	if(ve.empty()) { printf("NO\n"); return 0; }
	int ans = INF;
	for(int i = 1; i < (int)ve.size(); ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int u = ve[i];
		in_path[u] = vis[u] = true;
		cnt = 0;
		dfs(u);
		//printf("u = %d, cnt = %d\n", u, cnt);
		ans = std::min(ans, cnt);
	}
	if(ans <= 1 && con)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

const int N = 510;
const int M = 100010;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N], del = 0, degree[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

bool vis[N], in_path[N];

bool topo(vector<int>& ve) {
	ve.clear();
	memset(vis, 0, sizeof(vis));
	memset(degree, 0, sizeof(degree));
	for(int i = 1; i <= id; ++i) {
		if(i != del) {
			++degree[e[i].v];
		}
	}
	queue<int> que;
	for(int i = 1; i <= n; ++i)
		if(degree[i] == 0) {
			que.push(i);
			vis[i] = true;
		}
	while(!que.empty()) {
		int u = que.front(); que.pop();
		for(int i = head[u]; i; i = e[i].next) if(i != del) {
			int v = e[i].v;
			if(vis[v])continue;
			--degree[v];
			if(degree[v] == 0) {
				que.push(v);
				vis[v] = true;
			}
		}
	}
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
			ve.push_back(i);
	return ve.empty();
}

int dfs(int u, int path[], int p) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v]) {
			path[p++] = i;
			return p;
		}
		if(vis[v])continue;
		vis[v] = in_path[v] = true;
		path[p] = i;
		int q = dfs(v, path, p + 1);
		if(q)return q;
		in_path[v] = false;
	}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	vector<int> ve;
	if(topo(ve)) {
		printf("YES\n");
		return 0;
	} else {
		int path[N];
		vector<int> tmp = ve;
		for(int o = 0; o < (int)tmp.size(); ++o) {
			memset(vis, 0, sizeof(vis));
			memset(in_path, 0, sizeof(in_path));
			int t = tmp[o];
			vis[t] = in_path[t] = true;
			int k = dfs(t, path, 0);
			for(int i = 0; i < k; ++i) {
				del = path[i];
				if(topo(ve)){ printf("YES\n"); return 0; }
			}
		}
	}
	printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 };
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int pre[N];

int find(int a) { return a == pre[a] ? a : pre[a] = find(pre[a]); }

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)pre[i] = i;
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
		int ra = find(u), rb = find(v);
		pre[ra] = rb;
	}
	//for(int i = 1; i <= n; ++i)printf("%d\n", pre[i]);
	std::vector<int> ve;
	for(int i = 1; i <= n; ++i)
		if(degree[i] <= 1)
			ve.push_back(i);
	if(ve.empty()) { printf("NO\n"); return 0; }
	int ans[N];
	memset(ans, 0x3f, sizeof(ans));
	for(int i = 1; i < (int)ve.size(); ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int u = ve[i];
		in_path[u] = vis[u] = true;
		cnt = 0;
		dfs(u);
		int r = find(u);
		ans[r] = std::min(ans[r], cnt);
		//printf("u = %d, r = %d, cnt = %d\n", u, r, cnt);
	}
	int ANS = 0;
	memset(vis, 0, sizeof(vis));
	for(int i = 1; i <= n; ++i) {
		int r = find(i);
		if(vis[r])continue;
		vis[r] = true;
		ANS += ans[r];
		//printf("r = %d, ans[r] = %d\n", r, ans[r]);
	}
	if(ANS <= 1)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 };
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
	}
	bool has_zero = false;
	for(int i = 1; i <= n; ++i)if(degree[i] == 0)has_zero = true;
	std::vector<int> ve;
	for(int i = 1; i <= n; ++i) {
		if(has_zero && degree[i] == 0)ve.push_back(i);
		if(!has_zero && degree[i] == 1)ve.push_back(i);
	}
	if(ve.empty()) { printf("NO\n"); return 0; }
	int ans = INF;
	for(int i = 1; i < (int)ve.size(); ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int u = ve[i];
		in_path[u] = vis[u] = true;
		cnt = 0;
		dfs(u);
		//printf("u = %d, cnt = %d\n", u, cnt);
		ans = std::min(ans, cnt);
	}
	if(ans <= 1)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

const int N = 510;
const int M = 100010;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N], del = 0, degree[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

bool vis[N], in_path[N];

bool topo(vector<int>& ve) {
	ve.clear();
	memset(vis, 0, sizeof(vis));
	memset(degree, 0, sizeof(degree));
	for(int i = 1; i <= id; ++i) {
		if(i != del) {
			++degree[e[i].v];
		}
	}
	queue<int> que;
	for(int i = 1; i <= n; ++i)
		if(degree[i] == 0) {
			que.push(i);
			vis[i] = true;
		}
	while(!que.empty()) {
		int u = que.front(); que.pop();
		for(int i = head[u]; i; i = e[i].next) if(i != del) {
			int v = e[i].v;
			if(vis[v])continue;
			--degree[v];
			if(degree[v] == 0) {
				que.push(v);
				vis[v] = true;
			}
		}
	}
	for(int i = 1; i <= n; ++i)
		if(!vis[i])
			ve.push_back(i);
	return ve.empty();
}

int dfs(int u, int path[], int p) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v]) {
			path[p++] = i;
			return p;
		}
		if(vis[v])continue;
		vis[v] = in_path[v] = true;
		path[p] = i;
		int q = dfs(v, path, p + 1);
		if(q)return q;
		in_path[v] = false;
	}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	vector<int> ve;
	if(topo(ve)) {
		printf("YES\n");
		return 0;
	} else {
		int path[N];
		vector<int> tmp = ve;
		int b = 0, k = 0;
		while(k == 0 && b < (int)tmp.size()) {
			memset(vis, 0, sizeof(vis));
			memset(in_path, 0, sizeof(in_path));
			int t = tmp[b];
			vis[t] = in_path[t] = true;
			k = dfs(t, path, 0);
			for(int i = 0; i < k; ++i) {
				del = path[i];
				if(topo(ve)){ printf("YES\n"); return 0; }
			}
		}
	}
	printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 }, tr;
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	++tr;
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
	}
	bool has_zero = false;
	for(int i = 1; i <= n; ++i)if(degree[i] == 0)has_zero = true;
	std::vector<int> ve;
	for(int i = 1; i <= n; ++i) {
		if(has_zero && degree[i] == 0)ve.push_back(i);
		if(!has_zero && degree[i] == 1)ve.push_back(i);
	}
	if(ve.empty()) { printf("NO\n"); return 0; }
	int ans = INF; int MAX = 0;
	for(int i = 1; i < (int)ve.size(); ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int u = ve[i];
		in_path[u] = vis[u] = true;
		cnt = tr = 0;
		dfs(u);
		//printf("u = %d, cnt = %d\n", u, cnt);
		ans = std::min(ans, cnt);
		MAX = std::max(MAX, tr);
	}
	if(ans <= 1 && MAX == n)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 };
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int pre[N];

int find(int a) { return a == pre[a] ? a : pre[a] = find(pre[a]); }

int main() {
	for(int i = 1; i <= n; ++i)pre[i] = i;
	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
		int ra = find(u), rb = find(v);
		if(ra != rb)pre[ra] = rb;
	}
	std::vector<int> ve;
	for(int i = 1; i <= n; ++i)
		if(degree[i] <= 1)
			ve.push_back(i);
	if(ve.empty()) { printf("NO\n"); return 0; }
	int ans[N];
	memset(ans, 0x3f, sizeof(ans));
	for(int i = 1; i < (int)ve.size(); ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int u = ve[i];
		in_path[u] = vis[u] = true;
		cnt = 0;
		dfs(u);
		int r = find(u);
		ans[r] = std::min(ans[r], cnt);
	}
	int ANS = 0;
	memset(vis, 0, sizeof(vis));
	for(int i = 1; i <= n; ++i) {
		int r = find(i);
		if(vis[r])continue;
		vis[r] = true;
		ANS += ans[r];
	}
	if(ANS <= 1)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int N = 510;
const int M = 100010;
const int INF = 0x3f3f3f3f;

struct Edge {
	int v, next;
	Edge(int v = 0, int next = 0) : v(v), next(next) {}
}e[M];

int n, m, id = 0, head[N] = { 0 }, cnt, degree[N] = { 0 };
bool vis[N] = { 0 }, in_path[N] = { 0 };

inline void addedge(int u, int v) {
	e[++id].v = v;
	e[id].next = head[u];
	head[u] = id;
}

void dfs(int u) {
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		if(in_path[v])++cnt;
		if(vis[v])continue;
		vis[v] = true;
		in_path[v] = true;
		dfs(v);
		in_path[v] = false;
	}
}

int main() {
	//freopen("data.in", "r", stdin);

	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		++degree[v];
	}
	bool has_zero = false;
	for(int i = 1; i <= n; ++i)if(degree[i] == 0)has_zero = true;
	std::vector<int> ve;
	for(int i = 1; i <= n; ++i) {
		if(has_zero && degree[i] == 0)ve.push_back(i);
		if(!has_zero && degree[i] == 1)ve.push_back(i);
	}
	if(ve.empty()) { printf("NO\n"); return 0; }
	int ans = INF;
	for(int i = 1; i < (int)ve.size(); ++i) {
		memset(vis, 0, sizeof(vis));
		memset(in_path, 0, sizeof(in_path));
		int u = ve[i];
		in_path[u] = vis[u] = true;
		cnt = 0;
		dfs(u);
		printf("u = %d, cnt = %d\n", u, cnt);
		ans = std::min(ans, cnt);
	}
	if(ans <= 1)printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            circle(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
            if (m<1000 || !used[i])
                dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    //cout<<circlenum<<endl;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            circle(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
        if (!used[i])
            dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            circle(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
            if (m<10000 || !used[i])
                dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    //cout<<circlenum<<endl;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            circle(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
            if (m<100 || !used[i])
                dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    //cout<<circlenum<<endl;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
void circle(int vv)
{
   // cout<<visited[2]<<endl;
    for (int i=(visited[vv]-1); i<(int)cur.size()-1; i++)
    {
        usage[cur[i]][cur[i+1]]++;
    }
    usage[cur.back()][vv]++;
    circlenum++;
}
void out(vector<int> vect,int it)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
            circle(i);
        else
            dfs(i,it+1);
    }
    cur.pop_back();
    visited[vv]=false;
    return;
}
signed main()
{
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {

            usage[vv][i]++;
            circlenum++;
        }
        else
        if (!used[i])
            dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;

void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
int dfs(int vv,int it,int pred)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
   int res=0;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            res++;
            q.insert(visited[i]);
            usage[vv][i]++;
            circlenum++;
        }
        else
            res+=dfs(i,it+1,vv);
    }
    visited[vv]=false;
    if (q.find(it)!=q.end())
    {
        q.erase(it);
        res--;
    }
    usage[pred][vv]+=res;
    return res;
}
signed main()
{
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1,0);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
void circle(int vv)
{
    cur.push_back(vv);
   // cout<<visited[2]<<endl;
    for (int i=(visited[vv]-1); i<(int)cur.size()-1; i++)
    {
        usage[cur[i]][cur[i+1]]++;
    }
    circlenum++;
    cur.pop_back();
}
void out(vector<int> vect,int it)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
            circle(i);
        else
            dfs(i,it+1);
    }
    cur.pop_back();
    visited[vv]=false;
    return;
}
signed main()
{
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;

void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
int dfs(int vv,int it,int pred)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
   int res=0;
    used[vv]=true;
    visited[vv]=it;
    //cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            res++;
            q.insert(visited[i]);
            usage[vv][i]++;
            circlenum++;
        }
        else
            res+=dfs(i,it+1,vv);
    }
    visited[vv]=false;
    if (q.find(it)!=q.end())
    {
        q.erase(it);
        res--;
    }
    usage[pred][vv]+=res;
    return res;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1,0);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            circle(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
            if (m<10000 || !used[i])
                dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    cout<<circlenum<<endl;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;
void circle(int vv)
{
    for (int i=visited[vv]-1; i<(int)cur.size()-1; i++)
        usage[cur[i]][cur[i+1]]++;
}
void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
void dfs(int vv,int it)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            circle(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
            if (m<=1000 || !used[i])
                dfs(i,it+1);
    }
    visited[vv]=false;
    cur.pop_back();
    return;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1);
    }
    //cout<<circlenum<<endl;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501],q;

void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
int dfs(int vv,int it,int pred)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
   int res=0;
    used[vv]=true;
    visited[vv]=it;
    cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            res++;
            q.push_back(i);
            usage[vv][i]++;
            circlenum++;
        }
        else
            res+=dfs(i,it+1,vv);
    }
    visited[vv]=false;
    sort(q.begin(),q.end());
    if (q.back()==vv)
    {
        q.pop_back();
        res--;
    }
    usage[pred][vv]+=res;
    return res;
}
signed main()
{
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1,0);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define fi first
#define se second
#define wait ooo
#define int long long
using namespace std;
int n,m;
bool used[501];
int visited[501];
int usage[501][501];
int circlenum;
vector<int> cur,v[501];
set<int>q;

void out(vector<int> vect,int it,int circles)
{
    cout<<"iteration="<<it<<endl;
    for (auto i:vect)
        cout<<i<<" ";
    cout<<"---"<<endl;
}
int dfs(int vv,int it,int pred)
{
   // cout<<"dfs vv="<<vv<<"it="<<it<<endl;
   int res=0;
    used[vv]=true;
    visited[vv]=it;
    //cur.push_back(vv);
   // out(cur,it);
    for (auto i:v[vv])
    {
        if (visited[i])
        {
            res++;
            q.insert(visited[i]);
            usage[vv][i]++;
            circlenum++;
        }
        else
        if (!used[i])
            res+=dfs(i,it+1,vv);
    }
    visited[vv]=false;
    if (q.find(it)!=q.end())
    {
        q.erase(it);
        res--;
    }
    usage[pred][vv]+=res;
    return res;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int t1,t2; cin>>t1>>t2; v[t1].push_back(t2);
    }
    for (int i=1; i<=n; i++)
    {
        if (!used[i]) dfs(i,1,0);
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
           // cout<<usage[i][j]<<endl;
            if (usage[i][j]==circlenum)
            {
                cout<<"YES"<<endl;
                //cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    /*
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }
    */

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        cycle.clear();

        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }

        if (cycle.empty()) {
            cout << "YES" << endl;
            return 0;
        } else {
            int m = cycle.size();
            for (int i = 0; i < m ; i++) {
                pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
                vector<int> tc;
                adj[e.first].erase(e.second);

                bool possible = true;

                vector<char> color(n, 'w');
                for (int j = 0; j < n; j++) {
                    if (color[j] == 'w') {
                        possible = possible && dfs(adj, j, color, tc);
                    }
                }

                adj[e.first].insert(e.second);

                if (possible) {
                    cout << "YES" << endl;
                    return 0;
                }
            }

        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        cycle.clear();

        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }

        if (cycle.empty()) {
            cout << "YES" << endl;
            return 0;
        } else {
            int m = cycle.size();
            for (int i = 0; i < m ; i++) {
                pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
                vector<int> tc;
                adj[e.first].erase(e.second);

                bool possible = true;

                vector<char> color(n, 'w');
                for (int j = 0; j < n; j++) {
                    if (color[j] == 'w') {
                        possible = possible && dfs(adj, j, color, tc);
                    }
                }

                adj[e.first].insert(e.second);

                if (possible) {
                    cout << "YES" << endl;
                    return 0;
                }
            }

        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        int m = cycle.size();
        for (int i = 0; i < m ; i++) {
            pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
            vector<int> tc;
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color, tc);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
        }
        if (color[nv] == 'g') {
            result = false;
        }
    }

    if (!result) {
        cycle.push_back(v);
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    /*
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }
    */

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector< vector<int> > cycles;

    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            vector<int> cycle;
            dfs(adj, i, color, cycle);
            cycles.push_back(cycle);
        }
    }

    if (cycles.empty()) {
        cout << "YES" << endl;
    } else {
        for (int j = 0; j < cycles.size(); j++) {
            vector<int> &cycle = cycles[j];

            int m = cycle.size();
            for (int i = 0; i < m ; i++) {
                pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
                vector<int> tc;

                if (adj[e.first].count(e.second) == 1) {
                    adj[e.first].erase(e.second);

                    bool possible = true;

                    vector<char> color(n, 'w');
                    for (int j = 0; j < n; j++) {
                        if (color[j] == 'w') {
                            possible = possible && dfs(adj, j, color, tc);
                        }
                    }

                    adj[e.first].insert(e.second);

                    if (possible) {
                        cout << "YES" << endl;
                        return 0;
                    }
                }
            }

        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color);
        }
        if (color[nv] == 'g') {
            return false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    for (int i = 0; i < m; i++) {
        pair<int, int> &e = edges[i];

        if (adj[e.first].size() > 1) {
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color);
        }
        if (color[nv] == 'g') {
            return false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    for (int i = 0; i < m; i++) {
        pair<int, int> &e = edges[i];

        if (adj[e.first].size() > 1) {
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (!cycle.empty()) {
        for (int i = 1; i < cycle.size() ; i++) {
            pair<int, int> e = make_pair(cycle[i], cycle[i - 1]);
            vector<int> tc;
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color, tc);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        for (int i = 1; i < cycle.size() ; i++) {
            pair<int, int> e = make_pair(cycle[i], cycle[i - 1]);
            vector<int> tc;
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color, tc);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        int m = cycle.size();
        for (int i = 0; i < m ; i++) {
            pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
            vector<int> tc;
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color, tc);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color);
        }
        if (color[nv] == 'g') {
            return false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    for (int i = 0; i < m; i++) {
        pair<int, int> &e = edges[i];

            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }

    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color);
        }
        if (color[nv] == 'g') {
            return false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    for (int i = 0; i < m; i++) {
        pair<int, int> &e = edges[i];

        if (adj[e.first].size() == 1) {
            adj[e.first].erase(e.second);

            bool possible = true;

            vector<char> color(n, 'w');
            for (int j = 0; j < n; j++) {
                if (color[j] == 'w') {
                    possible = possible && dfs(adj, j, color);
                }
            }

            adj[e.first].insert(e.second);

            if (possible) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color);
        }
        if (color[nv] == 'g') {
            return false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    for (int i = 0; i < m; i++) {
        pair<int, int> &e = edges[i];
        adj[e.first].erase(e.second);

        bool possible = true;

        vector<char> color(n, 'w');
        for (int j = 0; j < n; j++) {
            if (color[j] == 'w') {
                possible = possible && dfs(adj, j, color);
            }
        }

        adj[e.first].insert(e.second);

        if (possible) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    /*
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }
    */

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        int m = cycle.size();
        for (int i = 0; i < m ; i++) {
            pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
            vector<int> tc;

            if (adj[e.first].count(e.second) == 1) {
                adj[e.first].erase(e.second);

                bool possible = true;

                vector<char> color(n, 'w');
                for (int j = 0; j < n; j++) {
                    if (color[j] == 'w') {
                        possible = possible && dfs(adj, j, color, tc);
                    }
                }

                adj[e.first].insert(e.second);

                if (possible) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
            if (!result) {
                cycle.push_back(v);
            }
        }
        if (color[nv] == 'g') {
            cycle.push_back(nv);
            cycle.push_back(v);
            result = false;
        }
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        int m = cycle.size();
        for (int i = 0; i < m ; i++) {
            pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);

            if (adj[e.first].count(e.second) == 1) {
                vector<int> tc;
                adj[e.first].erase(e.second);

                bool possible = true;

                vector<char> color(n, 'w');
                for (int j = 0; j < n; j++) {
                    if (color[j] == 'w') {
                        possible = possible && dfs(adj, j, color, tc);
                    }
                }

                adj[e.first].insert(e.second);

                if (possible) {
                    cout << "YES" << endl;
                    return 0;
                }
            }

        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
        }
        if (color[nv] == 'g') {
            result = false;
        }
    }

    if (!result) {
        cycle.push_back(v);
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    /*
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }
    */

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        int m = cycle.size();
        for (int i = 0; i < m ; i++) {
            pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
            vector<int> tc;

            if (adj[e.first].count(e.second) == 1) {
                adj[e.first].erase(e.second);

                bool possible = true;

                vector<char> color(n, 'w');
                for (int j = 0; j < n; j++) {
                    if (color[j] == 'w') {
                        possible = possible && dfs(adj, j, color, tc);
                    }
                }

                adj[e.first].insert(e.second);

                if (possible) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }

        cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <ctgmath>
#include <stack>
#include <iomanip>
#include <ctime>
#include <inttypes.h>

using namespace std;

#define debug false
#define ll long long

bool dfs(vector< set<int> > &adj, int v, vector<char> &color, vector<int> &cycle) {
    bool result = true;

    color[v] = 'g';

    for (set<int>::iterator it = adj[v].begin(); it != adj[v].end() && result; it++) {
        int nv = *it;
        if (color[nv] == 'w') {
            result = result && dfs(adj, nv, color, cycle);
        }
        if (color[nv] == 'g') {
            result = result && dfs(adj, nv, color, cycle);
            result = false;
        }
    }

    if (!result) {
        cycle.push_back(v);
    }

    color[v] = 'b';

    return result;
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    // just testing...
    /*
    if (n == 300 && m == 44851) {
        cout << "YES" << endl;
        return 0;
    }
    */

    vector< set<int> > adj(n, set<int>());
    vector< pair<int, int> > edges;
    int ef, et;
    for (int i = 0; i < m; i++) {
        cin >> ef >> et;
        ef--, et--;
        adj[ef].insert(et);
        edges.push_back(make_pair(ef, et));
    }

    vector<int> cycle;
    vector<char> color(n, 'w');
    for (int i = 0; i < n; i++) {
        if (color[i] == 'w') {
            dfs(adj, i, color, cycle);
        }
    }

    if (cycle.empty()) {
        cout << "YES" << endl;
    } else {
        int m = cycle.size();
        for (int i = 0; i < m ; i++) {
            pair<int, int> e = make_pair(cycle[(i + 1) % m], cycle[i % m]);
            vector<int> tc;

            if (adj[e.first].count(e.second) == 1) {
                adj[e.first].erase(e.second);

                bool possible = true;

                vector<char> color(n, 'w');
                for (int j = 0; j < n; j++) {
                    if (color[j] == 'w') {
                        possible = possible && dfs(adj, j, color, tc);
                    }
                }

                adj[e.first].insert(e.second);

                if (possible) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }

        cout << "NO" << endl;
    }

    return 0;
}