S=input() LEN=len(S) S+="z"*100 D1=[] D2=[] for i in range(LEN): if S[i:i+3]=="phn": ind=i+3 while S[ind:ind+2]=="om": ind+=2 #print(i,ind) D1.append((ind-(i+3))//2) for i in range(LEN): if S[i:i+2]=="om": ind=i-1 while ind>=0 and S[ind]=="h": ind-=1 #print(i,ind) if S[ind-2:ind+1]=="pen": ind2=i while S[ind2:ind2+2]=="om": ind2+=2 if (ind2-i)//2>0: D2.append((ind2-i)//2) if D1==[] and D2==[]: if "e" in S: print(2) elif "h" in S: print(1) else: print(0) else: if D2==[]: print(sum(D1)+max(D1)+1) elif D1==[]: print(sum(D2)+max(D2)+2) else: if max(D1)>max(D2): print(sum(D1)+sum(D2)+max(D1)+1) else: print(sum(D1)+sum(D2)+max(D2)+2)