N = int(input()) S = list(input()) if N == 2: print(1) exit() T = [] for i in range(N-1): if (S[i] == 'B') & (S[i+1] == 'B'): pass else: T.append(S[i]) if (S[-1] == 'B') & (S[-2] == 'B'): T.append('B') elif S[-1] == 'A': T.append('A') # print(''.join(T)) M = len(T) X = 0 for i in range(M-2): if (T[i] == 'B') & (T[i+2]=='B'): X += 1 ans = M - X if N == M: ans -= 1 print(ans)