#include<bits/stdc++.h>
using namespace std;

struct StronglyConnectedComponents
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};

int main(){
  int n,m; cin>>n>>m;
  StronglyConnectedComponents scc(n+1);
  for(int i=0;i<m;++i){
    int a,b; cin>>a>>b;
    scc.add_edge(a,b);
  }
  vector<vector<int> > buff;
  scc.build(buff);
  set<int> s[301];
  for(int i=1;i<=n;++i)
    for(int j=1;j<=n;++j)
      if(scc[i]==scc[j]) s[i].insert(j);
  
  for(int i=1;i<=n;++i){
    for(auto it=s[i].begin();it!=s[i].end();it++){
      if(it!=s[i].begin()) cout << " ";
      cout << *it;
    }
    cout << endl;
  }

  return 0;
}

