# 拓扑排序

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

int main(){
int N,M,in_degree[100],a,b,nodecount;
vector<int> edge[100*99/2];
queue<int> Q;
while(cin>>N>>M&&N){
//初始化
for(int m=0;m<N;m++){
in_degree[m]=0;
edge[m].clear();
}
while(!Q.empty()) Q.pop();
nodecount=0;
//读入数据
for(int i=0;i<M;i++){
cin>>a>>b;
edge[a].push_back(b);
in_degree[b]++;
}
for(int j=0;j<N;j++){
if(in_degree[j]==0)
Q.push(j);
}
while(!Q.empty()){
int node = Q.front();
Q.pop();
nodecount++;
for(int k=0;k<edge[node].size();k++){
in_degree[edge[node][k]]--;
if(in_degree[edge[node][k]]==0){
Q.push(edge[node][k]);
}
}
}
if(nodecount==N)
printf("YES\n");
else
printf("NO\n");

}
return 0;
}

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<string>
#include<map>
using namespace std;

int main(){
int n,sum;
string p1,p2;
map<string ,vector<string > > edge_map;
map<string,int> indegree;
while(cin>>n&&n){
int nodecount = 0;
edge_map.clear();
indegree.clear();
for(int i=0;i<n;i++){
cin>>p1>>p2;
edge_map[p1].push_back(p2);
if(indegree.find(p1)==indegree.end())
indegree[p1]=0;
if(indegree.find(p2)==indegree.end())
indegree[p2]=0;
indegree[p2]++;
}
map<string,int>::iterator it;
for(it=indegree.begin();it!=indegree.end();it++){
if(it->second==0){
nodecount ++;
}
}
if(nodecount==1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}