"""simple docstring"""



from __future__ import annotations
def 						_SCREAMING_SNAKE_CASE			(   __snake_case      :  Union[str, Any]   ):





  '''simple docstring'''





  global graph, reversed_graph, scc, component, visit, stack
  if visit[u]:
    return
  lowercase							   =	True
  for v in graph[u]:
    dfs(_lowerCAmelCase   )
  stack.append(_lowerCAmelCase   )
def 						_SCREAMING_SNAKE_CASE			(   __snake_case      :  List[str]   ):





  '''simple docstring'''





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





  '''simple docstring'''





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


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

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

    _UpperCamelCase		:  list[int]						=		[]
    _UpperCamelCase		:  list[bool]						=		[False] * n
    _UpperCamelCase		:  list[int]						=		[]
    _UpperCamelCase		:  list[int]						=		[]
    print(kosaraju())










"""simple docstring"""



def 						_SCREAMING_SNAKE_CASE			(   __snake_case      :  str   ):





  '''simple docstring'''





  lowercase							   =	len(__snake_case   )
  lowercase							   =	[0] * length
  lowercase							   =	[[False for i in range(__snake_case   )] for j in range(__snake_case   )]
  for i, c in enumerate(__snake_case   ):
    lowercase							   =	i
    for j in range(i + 1   ):
      if c == string[j] and (i - j < 2 or is_palindromic[j + 1][i - 1]):
        lowercase							   =	True
        lowercase							   =	min(__snake_case		, 0 if j == 0 else (cut[j - 1] + 1)   )
    lowercase							   =	mincut
  return cut[length - 1]


if __name__ == "__main__":
    _UpperCamelCase		:  List[Any]						=		input('Enter the string: ').strip()
    _UpperCamelCase		:  List[Any]						=		find_minimum_partitions(s)
    print(F'''Minimum number of partitions required for the \'{s}\' is {ans}''')


