#include <bits/stdc++.h>
using namespace std;vector<list<int>> graph; // 删除局部 graph,使用全局 graph
vector<vector<int>> res;
vector<int> path;
int N, M;void dfs(int index) {if (index == N) {res.push_back(path);return;}for (int now : graph[index]) {path.push_back(now);dfs(now);path.pop_back();}
}int main() {cin >> N >> M;graph.resize(N + 1); // 初始化 graph 大小while (M--) {int s, t;cin >> s >> t;graph[s].push_back(t);}path.push_back(1);dfs(1);if (res.size() == 0) {cout << -1 << endl;return 0; // 提前 return,避免后续输出错误结果}for (const vector<int> &pa : res) { // 使用正确的变量名 resfor (int i = 0; i < pa.size() - 1; i++) {cout << pa[i] << " ";}cout << pa[pa.size() - 1] << endl;}return 0;
}