#include <bits/stdc++.h>
using namespace std;
class graph {
int v;
int **adj;
public:
graph (int v) {
this->v= v;
adj= new int*[v];
for (int i=0; i<v; i++)
adj[i]= new int [v];
for (int i=0; i<v; i++)
for (int j=0; j<v; j++)
adj[i][j]= 0;
}
void addEdge (int u, int w) {
adj[u][w]=1;
adj[w][u]=1;
}
void dfs(int, bool [], vector <int> , int );
};
void graph::dfs (int s, bool visited[], vector <int> ans, int k) {
if (k<0) {
for (int i=0;i<ans.size();i++)
cout<< ans[i]<< " ";
cout<< "\n";
return;
}
visited[s]= 1;
ans.push_back(s);
for (int i=0;i<v;i++)
if (adj[s][i] && !visited[i])
dfs(i, visited, ans, k-1);
visited[s]= 0;
}
int main() {
int n, m;
cin>>n>>m;
graph g(n);
for (int i=0;i<m;i++) {
int a, b;
cin>> a>>b;
g.addEdge(a,b);
}
int k= 4;
bool visited[n]= {0};
vector <int> ans;
g.dfs (0, visited, ans, k);
}