import sys, math sys.setrecursionlimit(10**8) sys.set_int_max_str_digits(0) INF = 1e18 MOD = 998244353 from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter from itertools import product, combinations, permutations, groupby, accumulate from heapq import heapify, heappop, heappush from sortedcontainers import SortedList input = sys.stdin.readline def I(): return input().rstrip() def II(): return int(input().rstrip()) def IS(): return input().rstrip().split() def MII(): return map(int, input().rstrip().split()) def LI(): return list(input().rstrip()) def TII(): return tuple(map(int, input().rstrip().split())) def LII(): return list(map(int, input().rstrip().split())) def LSI(): return list(map(str, input().rstrip().split())) def GMI(): return list(map(lambda x: int(x) - 1, input().rstrip().split())) def kiriage(a, b): return (a+b-1)//b N = II() S = I() change_pattern = set() for i in range(N - 1): pos, nex = S[i], S[i + 1] if pos == nex == 'B': x = 10**10 elif pos == nex == 'A': x = (i + 1) * N + (i + 2) elif pos == 'A': x = i + 1 else: x = i + 2 change_pattern.add(x) ans = len(change_pattern) print(ans)