#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll mp[333][333];

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

    REP(i, 333)REP(j, 333)if(i != j)mp[i][j] = INF;

    ll n, m;cin >> n >> m;
    REP(i, m){
        ll a, b;cin >> a >> b;a--;b--;
        mp[a][b] = 0;
    }

    REP(k, 333)REP(i, 333)REP(j, 333)mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);

    REP(i, n){
        bool flag = false;
        REP(j, n){
            if(mp[i][j] == 0 && mp[j][i] == 0){
                if(flag)cout << " ";
                cout << (j + 1);
                flag = true;
            }
        }
        cout << endl;
    }

	return 0;
}

