output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
attempt: import sys
  
  
  fin = sys.stdin.readline
  N = int(fin())
  s_list = [fin().rstrip("\n") for _ in range(N)]
  num_AB_in_between = 0
  s_Bhoge = 0
  s_hogeA = 0
  s_BA = 0
  for s in s_list:
      if s[0] == "B" and s[-1] == "A":
          s_BA += 1
      elif s[0] == "B":
          s_Bhoge += 1
      elif s[-1] == "A":
          s_hogeA += 1
  
      for i, char in enumerate(s[:-1]):
          next_char = s[i + 1]
          if char == "A" and next_char == "B":
              num_AB_in_between += 1
  
  # print(s_Bhoge, s_hogeA, s_BA)
  if s_BA:
      num_AB_bound = 2 * s_BA - 2 + int(s_Bhoge > 0) + int(s_hogeA > 0)
      num_AB_bound += max(0, min(s_Bhoge - 1, s_hogeA - 1))
      # num_AB_bound += min(s_Bhoge - 1, s_hogeA - 1)
  else:
      num_AB_bound = min(s_Bhoge, s_hogeA)
  print(num_AB_in_between + num_AB_bound)
  
problem_description: Statement
  
  Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to
  Takahashi.
  
  How many ways are there to choose K consecutive integers?
samples: [{"input": "3 2", "output": "2\n    \n\nThere are two ways to choose two consecutive integers: (1,2) and (2,3).\n\n* * *"}, {"input": "13 3", "output": "11"}]