#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

template<class T> void print(vector<T> &vec) {
    for(int i = 0; i < (int)vec.size(); ++i) {
        if(i) cout << " ";
        cout << vec[i];
    }
    cout << "\n";
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    vector<vector<int>> visited(N, vector<int>(N));
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    function<void(int, int)> dfs = [&](int cur, int s) {
        visited[s][cur] = 1;
        for(auto &to : G[cur]) {
            if(!visited[s][to]) dfs(to, s);
        }
    };
    rep(i, 0, N) dfs(i, i);
    vector<vector<int>> ans(N);
    rep(i, 0, N) rep(j, 0, N) {
        if(visited[i][j] && visited[j][i]) ans[i].push_back(j + 1);
    }
    rep(i, 0, N) print(ans[i]);
    return 0;
}

