

'''simple docstring'''

from __future__ import annotations




def  UpperCamelCase(	UpperCAmelCase_      ):
 global graph, reversed_graph, scc, component, visit, stack
 if visit[u]:
  return
 UpperCAmelCase			:      Union[str, Any]		   =					True
 for v in graph[u]:
  dfs(UpperCAmelCase_      )
 stack.append(UpperCAmelCase_      )




def  UpperCamelCase(	UpperCAmelCase_      ):
 global graph, reversed_graph, scc, component, visit, stack
 if visit[u]:
  return
 UpperCAmelCase			:      int		   =					True
 component.append(UpperCAmelCase_      )
 for v in reversed_graph[u]:
  dfsa(UpperCAmelCase_      )




def  UpperCamelCase(	):
 global graph, reversed_graph, scc, component, visit, stack
 for i in range(UpperCAmelCase_      ):
  dfs(UpperCAmelCase_      )
 UpperCAmelCase			:      Optional[Any]		   =					[False] * n
 for i in stack[::-1]:
  if visit[i]:
   continue
  UpperCAmelCase			:      List[Any]		   =					[]
  dfsa(UpperCAmelCase_      )
  scc.append(UpperCAmelCase_      )
 return scc


if __name__ == "__main__":
 # n - no of nodes, m - no of edges
 lowercase__       ,    lowercase__            =     list(map(int, input().strip().split()))

 lowercase__            =     [[] for _ in range(n)]  # graph
 lowercase__            =     [[] for i in range(n)]  # reversed graph
 # input graph data (edges)
 for _ in range(m):
  lowercase__       ,    lowercase__            =     list(map(int, input().strip().split()))
  graph[u].append(v)
  reversed_graph[v].append(u)

 lowercase__            =     []
 lowercase__            =     [False] * n
 lowercase__            =     []
 lowercase__            =     []
 print(kosaraju())







'''simple docstring'''

def  UpperCamelCase(	UpperCAmelCase_ = 1_00      ):
 UpperCAmelCase			:      Optional[Any]		   =					[[0 for _ in range(UpperCAmelCase_      )] for _ in range(m + 1      )]
 for i in range(m + 1      ):
  UpperCAmelCase			:      Optional[int]		   =					1

 for n in range(m + 1      ):
  for k in range(1    ,			UpperCAmelCase_      ):
   memo[n][k] += memo[n][k - 1]
   if n > k:
    memo[n][k] += memo[n - k - 1][k]

 return memo[m][m - 1] - 1


if __name__ == "__main__":
 print(solution(int(input("Enter a number: ").strip())))




