s = input().strip() # Find the first occurrence of 'pain' pain_start = s.find('pain') if pain_start == -1: print(-1) else: # Extract the substring before the first 'pain' substring = s[:pain_start] count = 0 # Iterate through the substring to count 'pon's for i in range(len(substring) - 2): if substring[i] == 'p' and substring[i+1] == 'o' and substring[i+2] == 'n': count += 1 if count < 2: print(-1) else: print(count - 1)