S=input() LEN=len(S) S+="z"*100 D1=0 D2=0 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=max(D1,(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 D2=max(D2,(ind2-i)//2) ANS=max(D1*2+1,D2*2+2) if ANS==0: if "e" in S: print(2) elif "h" in S: print(1) else: print(0) else: print(ANS)