#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using Int = long long int;
using Real = long double;
using std::pair;
using std::string;
using std::tuple;
using std::vector;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = vector<vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

using std::stack;

struct SCC {
    Graph<> graph, rgraph;
    vector<bool> visited;
    stack<int> stk;
    vector<vector<int>> groups;
    vector<int> id;

    void dfs(int v) {
        if (visited[v]) return;
        visited[v] = true;
        for (auto e : graph[v]) dfs(e.dst);
        stk.push(v);
    }

    void rdfs(int v, int cur) {
        if (id[v] >= 0) return;
        id[v] = cur;
        groups[cur].push_back(v);
        for (auto e : rgraph[v]) rdfs(e.dst, cur);
    }

    SCC(Graph<>& graph)
        : graph(graph),
          rgraph(graph.size()),
          visited(graph.size(), false),
          id(graph.size(), -1) {
        for (int v = 0; v < graph.size(); ++v) {
            for (auto e : graph[v]) {
                rgraph[e.dst].emplace_back(e.dst, e.src);
            }
        }

        for (int v = 0; v < graph.size(); ++v) dfs(v);

        int cur = 0;
        while (!stk.empty()) {
            int v = stk.top();
            stk.pop();
            if (id[v] < 0) {
                groups.resize(groups.size() + 1);
                rdfs(v, cur);
                ++cur;
            }
        }
    }
};

int main() {
    int n, m;
    std::cin >> n >> m;

    Graph<> graph(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(u, v);
    }

    SCC scc(graph);
    for (int v = 0; v < n; ++v) {
        auto& ans = scc.groups[scc.id[v]];
        std::sort(ans.begin(), ans.end());
        for (int i = 0; i < ans.size(); ++i) {
            std::cout << ans[i] + 1 << " \n"[i + 1 == ans.size()];
        }
    }
    return 0;
}



Measured memory_bytes: 12508