#include<bits/stdc++.h>usingnamespace std;
vector<vector<int>> result;
vector<int> path;voiddfs(vector<vector<int>>&graph,int x,int n){if(x == n){
result.push_back(path);return;}for(int i =1; i <= n; i++){if(graph[x][i]!=0){
path.push_back(i);dfs(graph, i, n);
path.pop_back();}}}intmain(){int N, M;
cin >> N >> M;
vector<vector<int>>graph(N +1,vector<int>(N +1,0));int s, t;for(int i =0; i < M; i++){
cin >> s >> t;
graph[s][t]=1;}
path.push_back(1);dfs(graph,1, N);if(result.empty()){
cout <<-1;}for(auto& pa : result){for(int i =0; i < pa.size()-1; i++){
cout << pa[i]<<" ";}
cout << pa[pa.size()-1]<<"\n";}return0;}
#include<bits/stdc++.h>usingnamespace std;
vector<vector<int>> result;
vector<int> path;voiddfs(vector<list<int>>&graph,int x,int n){if(x == n){
result.push_back(path);return;}for(int i : graph[x]){
path.push_back(i);dfs(graph, i, n);
path.pop_back();}}intmain(){int N, M, s, t;
cin >> N >> M;
vector<list<int>>graph(N +1,list<int>());while(M--){
cin >> s >> t;
graph[s].push_back(t);}
path.push_back(1);dfs(graph,1, N);if(result.empty()){
cout <<-1;}for(auto& pa : result){for(int i =0; i < pa.size()-1; i++){
cout << pa[i]<<" ";}
cout << pa[pa.size()-1]<<"\n";}return0;}