#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define jaldi_kar() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int N = 1e5+1;
bool vis[N];
bool myStack[N];
int parent[N];
vector<int> graph[N];
int v = -1;
vector<int> ans;
bool dfs(int vertex){
vis[vertex] = true;
myStack[vertex] = true;
bool isCycleFound = false;
for(int child : graph[vertex]){
if(vis[child] && myStack[child]){
parent[child] = vertex;
v = child;
return true;
}
if(vis[child]) continue;
parent[child] = vertex;
isCycleFound |= dfs(child);
}
myStack[vertex] = false;
return isCycleFound;
}
void samadhan(){
int n , m;
cin >> n >> m;
for(int i=0;i<m;i++){
int u , v;
cin >> u >> v;
graph[u].push_back(v);
}
bool cycle_found = false;
for(int i=1;i<=n;i++){
if(vis[i]) continue;
if(dfs(i)){
cycle_found = true;
ans.push_back(v);
int temp = parent[v];
while(temp!=v){
ans.push_back(temp);
temp = parent[temp];
}
ans.push_back(v);
reverse(ans.begin() , ans.end());
cout << ans.size() <<"\n";
for(int x : ans) cout << x <<" ";
break;
}
}
if(!cycle_found) cout <<"IMPOSSIBLE";
}
int main()
{
jaldi_kar();
ll t;
t = 1;
for(int it=1;it<=t;it++) {
samadhan();
}
return 0;
}