def RunLengthEncoding(S): res = [] N = len(S) i = 0 while i < N: cnt = 1 while i < N - 1 and S[i] == S[i + 1]: cnt += 1 i += 1 res.append((S[i], cnt)) i += 1 return res N = int(input()) S = input() ans = 0 bb = 0 RLE = RunLengthEncoding(S) for i, (k, v) in enumerate(RLE): if k == "A": ans += v - 1 if v == 1: ans += 1 else: ans += i > 0 ans += i < len(RLE) - 1 else: if v > 1: bb = 1 print(ans + bb)