






from typing import Optional, Tuple

import flax.linen as nn
import jax
import jax.numpy as jnp
from configuration_hybrid_clip import HybridCLIPConfig
from flax.core.frozen_dict import FrozenDict

from transformers import FLAX_MODEL_MAPPING, FlaxCLIPVisionModel
from transformers.modeling_flax_utils import FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPOutput
from transformers.utils import logging


lowerCamelCase										=  logging.get_logger(__name__)

class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   __lowerCAmelCase      =						42
   __lowerCAmelCase      =						jnp.floataa

   def 			SCREAMING_SNAKE_CASE__				(    self:	Union[str, Any]	)  ->		List[Any]:


       """simple docstring"""



       _lowercase     =	self.config.text_config
       _lowercase     =	self.config.vision_config

       _lowercase     =	self.config.projection_dim
       _lowercase     =	text_config.hidden_size
       _lowercase     =	vision_config.hidden_size

       _lowercase     =	FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
       _lowercase     =	FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__   ,       snake_case__	).module_class

       _lowercase     =	text_module(snake_case__   ,       dtype=self.dtype	)
       _lowercase     =	vision_module(snake_case__   ,       dtype=self.dtype	)

       _lowercase     =	nn.Dense(
           self.projection_dim   ,       dtype=self.dtype   ,       kernel_init=jax.nn.initializers.normal(0.02	)   ,       use_bias=snake_case__   ,       )
       _lowercase     =	nn.Dense(
           self.projection_dim   ,       dtype=self.dtype   ,       kernel_init=jax.nn.initializers.normal(0.02	)   ,       use_bias=snake_case__   ,       )
       _lowercase     =	self.param('logit_scale'   ,       jax.nn.initializers.ones   ,       []	)

   def __call__(    self:	Any   ,       snake_case__:	Any=None   ,       snake_case__:	List[Any]=None   ,       snake_case__:	Dict=None   ,       snake_case__:	Dict=None   ,       snake_case__:	List[Any]=None   ,       snake_case__:	bool = True   ,       snake_case__:	Optional[Any]=None   ,       snake_case__:	int=None   ,       snake_case__:	int=None   ,       )  ->		Any:


       """simple docstring"""



       _lowercase     =	return_dict if return_dict is not None else self.config.return_dict

       _lowercase     =	self.vision_model(
           pixel_values=snake_case__   ,       deterministic=snake_case__   ,       output_attentions=snake_case__   ,       output_hidden_states=snake_case__   ,       return_dict=snake_case__   ,       )

       _lowercase     =	self.text_model(
           input_ids=snake_case__   ,       attention_mask=snake_case__   ,       token_type_ids=snake_case__   ,       position_ids=snake_case__   ,       deterministic=snake_case__   ,       output_attentions=snake_case__   ,       output_hidden_states=snake_case__   ,       return_dict=snake_case__   ,       )

       _lowercase     =	vision_outputs[1]
       _lowercase     =	self.visual_projection(snake_case__	)

       _lowercase     =	text_outputs[1]
       _lowercase     =	self.text_projection(snake_case__	)

       # normalized features
       _lowercase     =	image_embeds / jnp.linalg.norm(snake_case__   ,       axis=-1   ,       keepdims=snake_case__	)
       _lowercase     =	text_embeds / jnp.linalg.norm(snake_case__   ,       axis=-1   ,       keepdims=snake_case__	)

       # cosine similarity as logits
       _lowercase     =	jnp.exp(self.logit_scale	)
       _lowercase     =	jnp.matmul(snake_case__   ,       image_embeds.T	) * logit_scale
       _lowercase     =	logits_per_text.T

       if not return_dict:
           return (logits_per_image, logits_per_text, text_embeds, image_embeds, text_outputs, vision_outputs)

       return FlaxCLIPOutput(
           logits_per_image=snake_case__   ,       logits_per_text=snake_case__   ,       text_embeds=snake_case__   ,       image_embeds=snake_case__   ,       text_model_output=snake_case__   ,       vision_model_output=snake_case__   ,       )






class 					snake_case_							(       lowercase_      ):







   """simple docstring"""



   __lowerCAmelCase      =						HybridCLIPConfig
   __lowerCAmelCase      =						FlaxHybridCLIPModule

   def __init__(    self:	List[Any]   ,       snake_case__:	HybridCLIPConfig   ,       snake_case__:	Optional[Tuple] = None   ,       snake_case__:	int = 0   ,       snake_case__:	jnp.dtype = jnp.floataa   ,       **snake_case__:	Tuple   ,       )  ->		Tuple:


       """simple docstring"""



       if input_shape is None:
           _lowercase     =	((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

       _lowercase     =	self.module_class(config=snake_case__   ,       dtype=snake_case__   ,       **snake_case__	)
       super().__init__(snake_case__   ,       snake_case__   ,       input_shape=snake_case__   ,       seed=snake_case__   ,       dtype=snake_case__	)

   def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple   ,       snake_case__:	jax.random.PRNGKey   ,       snake_case__:	Tuple   ,       snake_case__:	FrozenDict = None	)  ->		FrozenDict:


       """simple docstring"""



       _lowercase     =	jnp.zeros(input_shape[0]   ,       dtype='i4'	)
       _lowercase     =	jnp.broadcast_to(jnp.arange(jnp.atleast_ad(snake_case__	).shape[-1]	)   ,       input_shape[0]	)
       _lowercase     =	jnp.ones_like(snake_case__	)
       _lowercase     =	jnp.ones_like(snake_case__	)

       _lowercase     =	jax.random.normal(snake_case__   ,       input_shape[1]	)

       _lowercase ,    _lowercase     =	jax.random.split(snake_case__	)
       _lowercase     =	{'params': params_rng, 'dropout': dropout_rng}

       return self.module.init(snake_case__   ,       snake_case__   ,       snake_case__   ,       snake_case__   ,       snake_case__   ,       snake_case__	)["params"]

   def __call__(    self:	Tuple   ,       snake_case__:	Optional[int]   ,       snake_case__:	Tuple   ,       snake_case__:	List[str]=None   ,       snake_case__:	Optional[int]=None   ,       snake_case__:	int=None   ,       snake_case__:	dict = None   ,       snake_case__:	jax.random.PRNGKey = None   ,       snake_case__:	bool = False   ,       snake_case__:	Optional[bool] = None   ,       snake_case__:	Optional[bool] = None   ,       snake_case__:	Optional[bool] = None   ,       )  ->		List[str]:


       """simple docstring"""



       _lowercase     =	output_attentions if output_attentions is not None else self.config.output_attentions
       _lowercase     =	(
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       _lowercase     =	return_dict if return_dict is not None else self.config.return_dict

       if position_ids is None:
           _lowercase     =	jnp.broadcast_to(jnp.arange(jnp.atleast_ad(snake_case__	).shape[-1]	)   ,       input_ids.shape	)

       if token_type_ids is None:
           _lowercase     =	jnp.zeros_like(snake_case__	)

       if attention_mask is None:
           _lowercase     =	jnp.ones_like(snake_case__	)

       # Handle any PRNG if needed
       _lowercase     =	{}
       if dropout_rng is not None:
           _lowercase     =	dropout_rng

       return self.module.apply(
           {'params': params or self.params}   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       jnp.array(snake_case__   ,       dtype=jnp.floataa	)   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       not train   ,       snake_case__   ,       snake_case__   ,       snake_case__   ,       rngs=snake_case__   ,       )

   def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	Optional[Any]   ,       snake_case__:	Optional[int]=None   ,       snake_case__:	int=None   ,       snake_case__:	List[str]=None   ,       snake_case__:	dict = None   ,       snake_case__:	jax.random.PRNGKey = None   ,       snake_case__:	Optional[Any]=False   ,       )  ->		Union[str, Any]:


       """simple docstring"""



       if position_ids is None:
           _lowercase     =	jnp.broadcast_to(jnp.arange(jnp.atleast_ad(snake_case__	).shape[-1]	)   ,       input_ids.shape	)

       if token_type_ids is None:
           _lowercase     =	jnp.zeros_like(snake_case__	)

       if attention_mask is None:
           _lowercase     =	jnp.ones_like(snake_case__	)

       # Handle any PRNG if needed
       _lowercase     =	{}
       if dropout_rng is not None:
           _lowercase     =	dropout_rng

       def _get_features(snake_case__:	Tuple   ,       snake_case__:	List[Any]   ,       snake_case__:	Optional[Any]   ,       snake_case__:	Tuple   ,       snake_case__:	Union[str, Any]   ,       snake_case__:	Union[str, Any]	):
           _lowercase     =	module.text_model(
               input_ids=snake_case__   ,       attention_mask=snake_case__   ,       position_ids=snake_case__   ,       token_type_ids=snake_case__   ,       deterministic=snake_case__   ,       )
           _lowercase     =	text_outputs[1]
           _lowercase     =	module.text_projection(snake_case__	)
           return text_features

       return self.module.apply(
           {'params': params or self.params}   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       jnp.array(snake_case__   ,       dtype='i4'	)   ,       not train   ,       method=_get_features   ,       rngs=snake_case__   ,       )

   def 			SCREAMING_SNAKE_CASE__				(    self:	Dict   ,       snake_case__:	str   ,       snake_case__:	dict = None   ,       snake_case__:	jax.random.PRNGKey = None   ,       snake_case__:	Optional[int]=False	)  ->		Union[str, Any]:


       """simple docstring"""



       _lowercase     =	{}
       if dropout_rng is not None:
           _lowercase     =	dropout_rng

       def _get_features(snake_case__:	Any   ,       snake_case__:	Dict   ,       snake_case__:	Any	):
           _lowercase     =	module.vision_model(pixel_values=snake_case__   ,       deterministic=snake_case__	)
           _lowercase     =	vision_outputs[1]  # pooled_output
           _lowercase     =	module.visual_projection(snake_case__	)
           return image_features

       return self.module.apply(
           {'params': params or self.params}   ,       jnp.array(snake_case__   ,       dtype=jnp.floataa	)   ,       not train   ,       method=_get_features   ,       rngs=snake_case__   ,       )

   @classmethod
   def 			SCREAMING_SNAKE_CASE__				(    cls:	Optional[Any]   ,       snake_case__:	str = None   ,       snake_case__:	str = None   ,       *snake_case__:	List[str]   ,       **snake_case__:	Optional[Any]   ,       )  ->		FlaxPreTrainedModel:


       """simple docstring"""



       _lowercase     =	{
           argument[len('text_'	) :]: value for argument, value in kwargs.items() if argument.startswith('text_'	)
       }

       _lowercase     =	{
           argument[len('vision_'	) :]: value for argument, value in kwargs.items() if argument.startswith('vision_'	)
       }

       # remove text, vision kwargs from kwargs
       for key in kwargs_text.keys():
           del kwargs["text_" + key]
       for key in kwargs_vision.keys():
           del kwargs["vision_" + key]

       # Load and initialize the text and vision model
       _lowercase     =	kwargs_text.pop('model'   ,       snake_case__	)
       if text_model is None:
           assert (
               text_model_name_or_path is not None
           ), "If `model` is not defined as an argument, a `text_model_name_or_path` has to be defined"
           from transformers import FlaxAutoModel

           if "config" not in kwargs_text:
               from transformers import AutoConfig

               _lowercase     =	AutoConfig.from_pretrained(snake_case__	)
               _lowercase     =	text_config

           _lowercase     =	FlaxAutoModel.from_pretrained(snake_case__   ,       *snake_case__   ,       **snake_case__	)

       _lowercase     =	kwargs_vision.pop('model'   ,       snake_case__	)
       if vision_model is None:
           assert (
               vision_model_name_or_path is not None
           ), "If `model` is not defined as an argument, a `vision_model_name_or_path` has to be defined"
           from transformers import FlaxAutoModel

           if "config" not in kwargs_vision:
               from transformers import AutoConfig

               _lowercase     =	AutoConfig.from_pretrained(snake_case__	)
               _lowercase     =	vision_config

           _lowercase     =	FlaxAutoModel.from_pretrained(snake_case__   ,       *snake_case__   ,       **snake_case__	)

       # instantiate config with corresponding kwargs
       _lowercase     =	kwargs.pop('dtype'   ,       jnp.floataa	)
       _lowercase     =	HybridCLIPConfig.from_text_vision_configs(text_model.config   ,       vision_model.config   ,       **snake_case__	)

       # init model
       _lowercase     =	cls(snake_case__   ,       *snake_case__   ,       dtype=snake_case__   ,       **snake_case__	)

       if vision_config.model_type == "clip":
           _lowercase     =	vision_model.params['vision_model']
           _lowercase     =	vision_model.params['visual_projection']['kernel']
       else:
           _lowercase     =	vision_model.params

       _lowercase     =	text_model.params

       return model








from __future__ import annotations
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



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


    '''simple docstring'''



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


    '''simple docstring'''



    global graph, reversed_graph, scc, component, visit, stack
    for i in range(_lowercase      ):
        dfs(_lowercase      )
    _lowercase     =	[False] * n
    for i in stack[::-1]:
        if visit[i]:
            continue
        _lowercase     =	[]
        dfsa(_lowercase      )
        scc.append(_lowercase      )
    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())
