#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 260;
int n, m;
int f[maxn];
vector<int> res[maxn];
int getfather(int x) {
if(f[x] == x) return x;
return f[x] = getfather(f[x]);
}
void Merge(int a, int b) {
int v1 = getfather(a);
int v2 = getfather(b);
if(v1 != v2) {
if(v1 > v2) {
f[v1] = v2;
}
else {
f[v2] = v1;
}
}
}
void init() {
int i;
for(i = 0; i < n; i++) {
res[i].clear();
}
for(i = 0; i < n; i++) {
f[i] = i;
}
}
void work() {
int parent;
int i, j;
for( i = 0; i < n; i++) {
parent = getfather(i);
res[parent].push_back(i);
}
for( i = 0; i < n; i++) {
if(res[i].begin() != res[i].end())
sort(res[i].begin(), res[i].end());
}
for( i = 0; i < n; i++) {
if(res[i].size() == 0) continue;
if(res[i].size() >= 2) {
for( j = 0; j < (int)(res[i].size()-1); j++) {
printf("%d ", res[i][j]);
}
printf("%d\n", res[i][j]);
}
else {
printf("%d\n", res[i][0]);
}
}
cout << endl;
}
int main()
{
int from, to;
while(scanf("%d%d", &n, &m) != EOF) {
init();
for(int i = 0; i < m; i++) {
scanf("%d%d", &from, &to);
Merge(from, to);
}
work();
}
return 0;
}