Problem: You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order.

Constraints

* 1 \leq N \leq 500,000
* 1 \leq M \leq 500,000
* 0 \leq a_i, b_i < N

Input

Input is given from Standard Input in the following format:


N M
a_0 b_0
a_1 b_1
:
a_{M - 1} b_{M - 1}


Output

Print 1+K lines, where K is the number of strongly connected components. Print K on the first line. Print the information of each strongly connected component in next K lines in the following format, where l is the number of vertices in the strongly connected component and v_i is the index of the vertex in it.


l v_0 v_1 ... v_{l-1}


Here, for each edge (a_i, b_i), b_i should not appear in earlier line than a_i.

If there are multiple correct output, print any of them.

Example

Input

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2


Output

4
1 5
2 4 1
1 2
2 3 0

Solution (in PYTHON3):

Solution:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class DAG:
    def __init__(self, n, AB):
        self.n = n
        self.G = [[] for _ in range(n)]
        self.revG = [[] for _ in range(n)]
        self.AB = AB
        for a, b in AB:
            self.G[a].append(b)
            self.revG[b].append(a)

    def scc(self):
        visited = [False] * self.n
        order = []
        for i in range(self.n):
            if visited[i]: continue

            q = deque([i])
            visited[i] = True
            while q:
                v = q[-1]
                for u in self.G[v]:
                    if not visited[u]:
                        q.append(u)
                        visited[u] = True
                        break
                else:
                    #全て訪問済みの時
                    q.pop()
                    order.append(v)

        visited = [False] * self.n
        scc = []
        for i in order[::-1]:
            if visited[i]: continue
            tmp = [i]
            visited[i] = True
            q = deque([i])

            while q:
                v = q.pop()
                for u in self.revG[v]:
                    if visited[u]: continue
                    visited[u] = True
                    tmp.append(u)
                    q.append(u)
            scc.append(tmp)

        return scc



def main():
    N, M = LI()
    AB = LIR(M)
    g = DAG(N, AB)
    scc = g.scc()
    print(len(scc))
    for es in scc:
        print(len(es), *es)


if __name__ == '__main__':
    main()