import java.util.*;
public class Main {
static Scanner in = new Scanner(System.in);
static int N = 100;
static int[][] G = new int[N][N];
static int[] path = new int[N];
static int[] visited = new int[N];
static int m,n, pos;
static int dfs(int u, int pre){
int i;
visited[u] = -1;
path[u] = pre;
for (i = 0; i < n;i++){
if (G[u][i]!=0&&i!=pre){
if (visited[i]<0){
pos = u;
return 0;
}
if (dfs(i,u)==0) return 0;
}
}
visited[u] = 1;
return 1;
}
static void print(int u){
if (u<0){
return;
}
print(path[u]);
System.out.print(u+" ");
}
public static void main(String[] args) {
int i,s,e;
n = in.nextInt();
m = in.nextInt();
for (i = 0; i < m;i++){
s = in.nextInt();
e = in.nextInt();
G[s][e] = 1;
}
pos = -1;
for (i = 0; i < n;i++){
if (visited[i]==0&&dfs(i,-1)==0){
break;
}
}
if (pos<0){
System.out.println("不存在环!");
} else{
System.out.println("存在环!");
print(pos);
}
}
}