import java.util.ArrayList;
import java.util.Scanner;
import java.util.LinkedList;
/**
*
* @author cteam023
*/
public class Fn {
private static void vypisVysledek(Kolekce[] pole){
ArrayList<Integer> trojkovy = new ArrayList<Integer>();
for (int i = 0; i < pole.length; i++){
if ( pole[i].s.size()>= 4){
return;
}
if (pole[i].s.size() == 3){
trojkovy.add(i);
}
}
if (trojkovy.size() > 1){
for (int i = 0; i < trojkovy.size(); i++){
for (int j = i + 1; j < trojkovy.size(); j++){
if (existujeSpojeni(pole, i, j)){
return;
}
}
}
}
}
private static boolean existujeSpojeni(Kolekce[] pole, int bod1, int bod2){
LinkedList<Integer> fronta = new LinkedList<Integer>();
fronta.addFirst(bod1);
ArrayList<Integer> expand = new ArrayList<Integer>();
ArrayList<Integer> closed = new ArrayList<Integer>();
int tmp;
while (fronta.size() > 0){
tmp = fronta.getLast();
if (tmp == bod2){
return true;
}
closed.add(tmp);
for (Spojeni i: pole[tmp].s){
expand.add(i.getDruhy(tmp));
}
expand.removeAll(closed);
expand.removeAll(fronta);
fronta.removeLast();
fronta.addAll(expand);
}
return false;
}
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in); int pocetBodu, pocetCar;
Kolekce[] pole;
int bod1, bod2;
Spojeni spojeni;
while(sc.hasNextInt()){
pocetBodu = sc.nextInt();
pocetCar = sc.nextInt();
pole = new Kolekce[pocetBodu];
for (int i = 0; i < pole.length; i++){
pole[i] = new Kolekce();
pole[i].s = new ArrayList<Spojeni>();
}
for (int i = 0; i < pocetCar; i++){
bod1 = sc.nextInt() -1;
bod2 = sc.nextInt() -1;
spojeni = new Spojeni(bod1, bod2);
pole[bod1].s.add(spojeni);
pole[bod2].s.add(spojeni);
}
vypisVysledek(pole);
}
}
private static class Spojeni{
public int bod1, bod2;
public Spojeni(int bod1, int bod2){
this.bod1 = bod1;
this.bod2 = bod2;
}
public int getDruhy(int bod){
if(bod == bod1){
return bod2;
}
return bod1;
}
}
private static class Kolekce{
public ArrayList<Spojeni> s;
}
}