fn.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class fn {
private static class V{
List<Integer> s;
boolean n;
public V() {
n = false;
s = new ArrayList<Integer>();
}
}
Pattern p=Pattern.compile("\\s");
while((line=buf.readLine())!=null){
String[] vstup
= p.
split(line
); int m
= Integer.
parseInt(vstup
[0]); int n
= Integer.
parseInt(vstup
[1]); V[] graf = new V[m+1];
for(int i=1; i<=m; i++){
graf[i] = new V();
}
for(int i=0; i<n; i++){
line = buf.readLine();
vstup = p.split(line);
int a
= Integer.
parseInt(vstup
[0]); int b
= Integer.
parseInt(vstup
[1]); graf[a].s.add(b);
graf[b].s.add(a);
}
boolean res = false;
for(int i=1; i<=m; i++){
if(graf[i].s.size()==4){
boolean vysl = true;
for(int sus: graf[i].s){
vysl = vysl && graf[sus].s.size()==1;
}
res = res || vysl;
}
}
System.
out.
println(res
? "YES" : "NO");
}
}
}