N = int(input()) S = input() result = 0 i = -1 while i < N: i = S.find('U', i + 1) if i == -1: break j = i while j < N: j = S.find('M', j + 1) if j == -1: break k = j while k < N: k = S.find('G', k + 1) if k == -1: break if j - i != k - j: continue result += 1 #print(i, j, k) print(result)