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