import os
import sys
import time

from . import transposition_cipher as trans_cipher






def    __lowerCamelCase	(		):
       lowerCAmelCase__  			=      'Prehistoric Men.txt'
       lowerCAmelCase__  			=      'Output.txt'
       lowerCAmelCase__  			=      int(input('Enter key: '			)			)
       lowerCAmelCase__  			=      input('Encrypt/Decrypt [e/d]: '			)

       if not os.path.exists(lowerCAmelCase__			):
              print(F"""File {input_file} does not exist. Quitting..."""			)
              sys.exit()
       if os.path.exists(lowerCAmelCase__			):
              print(F"""Overwrite {output_file}? [y/n]"""			)
              lowerCAmelCase__  			=      input('> '			)
              if not response.lower().startswith('y'			):
                     sys.exit()

       lowerCAmelCase__  			=      time.time()
       if mode.lower().startswith('e'			):
              with open(lowerCAmelCase__			) as f:
                     lowerCAmelCase__  			=      f.read()
              lowerCAmelCase__  			=      trans_cipher.encrypt_message(lowerCAmelCase__			,						lowerCAmelCase__			)
       elif mode.lower().startswith('d'			):
              with open(lowerCAmelCase__			) as f:
                     lowerCAmelCase__  			=      f.read()
              lowerCAmelCase__  			=      trans_cipher.decrypt_message(lowerCAmelCase__			,						lowerCAmelCase__			)

       with open(lowerCAmelCase__			,						'w'			) as output_obj:
              output_obj.write(lowerCAmelCase__			)

       lowerCAmelCase__  			=      round(time.time() - start_time			,						2			)
       print(('Done (', total_time, 'seconds )')			)


if __name__ == "__main__":
    main()

from __future__ import annotations






def    __lowerCamelCase	(		lowerCAmelCase__			):
       global graph, reversed_graph, scc, component, visit, stack
       if visit[u]:
              return
       lowerCAmelCase__  			=      True
       for v in graph[u]:
              dfs(lowerCAmelCase__			)
       stack.append(lowerCAmelCase__			)






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






def    __lowerCamelCase	(		):
       global graph, reversed_graph, scc, component, visit, stack
       for i in range(lowerCAmelCase__			):
              dfs(lowerCAmelCase__			)
       lowerCAmelCase__  			=      [False] * n
       for i in stack[::-1]:
              if visit[i]:
                     continue
              lowerCAmelCase__  			=      []
              dfsa(lowerCAmelCase__			)
              scc.append(lowerCAmelCase__			)
       return scc


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

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

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