/*  -*- coding: utf-8 -*-
 *
 * 3102.cc: iff
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300;

/* typedef */

/* global variables */

bool ms[MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) ms[i][i] = true;

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    ms[a][b] = true;
  }

  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
	ms[i][j] = ms[i][j] || (ms[i][k] && ms[k][j]);

  for (int i = 0; i < n; i++) {
    for (int j = 0, cont = 0; j < n; j++)
      if (ms[i][j] && ms[j][i]) {
	if (cont) putchar(' ');
	printf("%d", j + 1);
	cont = 1;
      }
    putchar('\n');
  }  

  return 0;
}

