import re n=int(input()) s=input() a=0 for i in range(n//2): x=r"(?=(U"+'.'*i+r"M"+'.'*i+r"G))" a+=len(re.findall(x,s)) print(a)