output_description: If S consists of exactly two kinds of characters which both appear twice in S,
  print `Yes`; otherwise, print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
attempt: import sys
  
  
  def input():
      return sys.stdin.readline()[:-1]
  
  
  NM = list(map(int, input().split()))
  N = NM[0]
  M = NM[1]
  graph = [[] for j in range(N)]
  
  for i in range(M):
      edge = list(map(int, input().split()))
      graph[edge[0] - 1].append(edge[1] - 1)
  
  ST = list(map(int, input().split()))
  S = ST[0] - 1
  T = ST[1] - 1
  
  
  first = []
  second = []
  third = []
  able = [S]
  
  step = 0
  
  while True:
      first = []
      second = []
      third = []
      judge = 0
      for i in range(len(able)):
          for j in range(len(graph[able[i]])):
              if not (graph[able[i]][j] in first):
                  first.append(graph[able[i]][j])
      for i in range(len(first)):
          for j in range(len(graph[first[i]])):
              if not (graph[first[i]][j] in second):
                  second.append(graph[first[i]][j])
      for i in range(len(second)):
          for j in range(len(graph[second[i]])):
              if not (graph[second[i]][j] in third):
                  third.append(graph[second[i]][j])
      for i in range(len(third)):
          if not third[i] in able:
              able.append(third[i])
              judge = 1
      if judge == 0:
          print(-1)
          break
      step += 1
      if T in able:
          print(step)
          break
  
problem_description: Statement
  
  You are given a 4-character string S consisting of uppercase English letters.
  Determine if S consists of exactly two kinds of characters which both appear
  twice in S.
samples: [{"input": "ASSA", "output": "Yes\n    \n\nS consists of `A` and `S` which both appear twice in S.\n\n* * *"}, {"input": "STOP", "output": "No\n    \n\n* * *"}, {"input": "FFEE", "output": "Yes\n    \n\n* * *"}, {"input": "FREE", "output": "No"}]