output_description: Find the number of strings, modulo 998244353, that can result from applying
  the operation on S between 0 and K times (inclusive).
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S K
attempt: import sys
  
  readline = sys.stdin.readline
  # 非再帰
  import sys
  
  
  def scc(Edge):
      N = len(Edge)
      Edgeinv = [[] for _ in range(N)]
      for vn in range(N):
          for vf in Edge[vn]:
              Edgeinv[vf].append(vn)
  
      used = [False] * N
      order = []
      for st in range(N):
          if not used[st]:
              used[st] = True
              stack = [~st, st]
              while stack:
                  vn = stack.pop()
                  if vn >= 0:
                      for vf in Edge[vn]:
                          if not used[vf]:
                              used[vf] = True
                              stack.append(~vf)
                              stack.append(vf)
                  else:
                      order.append(~vn)
  
      res = [None] * N
      used = [False] * N
      cnt = -1
      for st in order[::-1]:
          if not used[st]:
              cnt += 1
              stack = [st]
              res[st] = cnt
              used[st] = True
              while stack:
                  vn = stack.pop()
                  for vf in Edgeinv[vn]:
                      if not used[vf]:
                          used[vf] = True
                          res[vf] = cnt
                          stack.append(vf)
      M = cnt + 1
      components = [[] for _ in range(M)]
      for i in range(N):
          components[res[i]].append(i)
      """
      tEdge = [[] for _ in range(M)]
      teset = set()
      for vn in range(N):
          tn = res[vn]
          for vf in Edge[vn]:
              tf = res[vf]
              if tn != tf and tn*M + tf not in teset:
                  teset.add(tn*M + tf)
                  tEdge[tn].append(tf)
      """
      return res, components
  
  
  N, M = map(int, readline().split())
  Edge = [[] for _ in range(N)]
  for _ in range(M):
      a, b = map(int, readline().split())
      Edge[a].append(b)
  
  R, comp = scc(Edge)
  Ans = [str(len(comp))]
  
  for c in comp:
      Ans.append(f"{len(c)} " + " ".join(map(str, c)))
  
  print("\n".join(Ans))
  
problem_description: Statement
  
  Given is a string S consisting of `0` and `1`. Find the number of strings,
  modulo 998244353, that can result from applying the following operation on S
  between 0 and K times (inclusive):
  
    * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
samples: [{"input": "0101 1", "output": "4\n    \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n    \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]