import sys, math sys.setrecursionlimit(1000000) INF = 1 << 100 #mod = 1000000007 mod = 998244353 input = lambda: sys.stdin.readline().rstrip() li = lambda: list(map(int, input().split())) N = int(input()) S = list(input()) ans = N-1 for i in range(1, N-1): if S[i-1] == S[i+1] == 'B': ans -= 1 flg = 0 for i in range(N-1): if S[i] == S[i+1] == 'B': ans -= 1 flg = 1 print(ans + flg)