import math import sys n = int(input()) s = input() idx_1 = 0 ans = 0 for i in s: idx_1 += 1 if i == 'U': idx_2 = idx_1 for j in s[idx_1:]: idx_2 += 1 if j == 'M' and idx_2+(idx_2-idx_1)-1 <= n and s[idx_2+(idx_2-idx_1)-1]=='G': ans += 1 print(ans)