





from __future__ import annotations




def 			lowerCAmelCase_			(				UpperCamelCase_	)  ->		str:
       global graph, reversed_graph, scc, component, visit, stack
       if visit[u]:
              return
       UpperCamelCase_ 							=	True
       for v in graph[u]:
              dfs(UpperCamelCase_	)
       stack.append(UpperCamelCase_	)




def 			lowerCAmelCase_			(				UpperCamelCase_	)  ->		Union[str, Any]:
       global graph, reversed_graph, scc, component, visit, stack
       if visit[u]:
              return
       UpperCamelCase_ 							=	True
       component.append(UpperCamelCase_	)
       for v in reversed_graph[u]:
              dfsa(UpperCamelCase_	)




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


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

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

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








from __future__ import annotations




def 			lowerCAmelCase_			(				UpperCamelCase_	)  ->		int | None:
       for r in range(1       ,		UpperCamelCase_	):
              UpperCamelCase_ 							=	[]
              for x in range(n - 1	):
                     UpperCamelCase_ 							=	pow(UpperCamelCase_       ,		UpperCamelCase_       ,		UpperCamelCase_	)
                     if val in li:
                            break
                     li.append(UpperCamelCase_	)
              else:
                     return r
       return None


if __name__ == "__main__":
     _UpperCAmelCase										=					int(input('Enter a prime number q: '))
     _UpperCAmelCase										=					find_primitive(q)
     if a is None:
          print(f'''Cannot find the primitive for the value: {a!r}''')
     else:
          _UpperCAmelCase										=					int(input('Enter private key of A: '))
          _UpperCAmelCase										=					pow(a, a_private, q)
          _UpperCAmelCase										=					int(input('Enter private key of B: '))
          _UpperCAmelCase										=					pow(a, b_private, q)

          _UpperCAmelCase										=					pow(b_public, a_private, q)
          _UpperCAmelCase										=					pow(a_public, b_private, q)

          print('The key value generated by A is: ', a_secret)
          print('The key value generated by B is: ', b_secret)

