import sys input = sys.stdin.readline N=int(input()) S=list(input().strip()) ANS=0 x=S.pop() if x!="Y": ANS+=1 x=S.pop() if x!="P": ANS+=1 x=S.pop() if x!="P": ANS+=1 x=S.pop() if x!="A": ANS+=1 x=S.pop() if x!="H": ANS+=1 for i in range(len(S)): if S[i:i+5]==["H","A","P","P","Y"]: ANS+=1 print(ANS)