def main(): length = int(input()) strings = input() if length == 2: print(1) return BB_found = False counter = 0 current_idx = 0 while current_idx < length-1: a_idx = strings.find("A", current_idx) if a_idx == 0: counter += 1 current_idx = 1 continue if a_idx == length - 1: if strings[a_idx-1] == "B": counter += 1 break if a_idx != -1: previous_2letters = strings[a_idx-1:a_idx+1] if previous_2letters == "AA": counter += 1 else: if strings[a_idx+1] == "A": counter += 2 else: counter += 1 diff = a_idx - current_idx if diff >= 2: BB_found = True current_idx = a_idx + 1 else: BB_found = True break if BB_found: counter += 1 print(counter) if __name__ == "__main__": main()