s = input().strip() count = 0 while True: applied_1 = 0 # Apply operation 1 as many times as possible s_list = list(s) new_s = [] i = 0 n = len(s_list) while i <= n - 5: if (s_list[i] == 'p' and s_list[i+1] == 'h' and s_list[i+2] == 'n' and s_list[i+3] == 'o' and s_list[i+4] == 'm'): new_s.extend(['p', 'e', 'n', 'h']) applied_1 += 1 i += 5 else: new_s.append(s_list[i]) i += 1 # Add remaining characters while i < n: new_s.append(s_list[i]) i += 1 new_s_str = ''.join(new_s) if applied_1 > 0: count += applied_1 s = new_s_str # Now apply operation 2 once # Remove all 'h's and replace 'e's with 'h's temp_list = [] e_count = 0 for c in s: if c != 'h': temp_list.append(c) if c == 'e': e_count += 1 # Replace 'e's with 'h's temp_list = ['h' if c == 'e' else c for c in temp_list] new_s_after_op2 = ''.join(temp_list) if new_s_after_op2 != s: count += 1 s = new_s_after_op2 else: break # No change, can't apply operation 2 else: # Try to apply operation 2 once temp_list = [] e_count = 0 for c in s: if c != 'h': temp_list.append(c) if c == 'e': e_count += 1 # Replace 'e's with 'h's temp_list = ['h' if c == 'e' else c for c in temp_list] new_s_after_op2 = ''.join(temp_list) if new_s_after_op2 != s: count += 1 s = new_s_after_op2 else: break # No more operations possible print(count)