#!/usr/bin/env python3 import sys def main(): # N = int(input()) # N, X = map(int,input().split()) # A = list(map(int,input().split())) S = input() N = len(S) if N < 10: print(-1) return c = 0 for i in range(N - 3): if S[i:(i + 3)] == "pon": c += 1 if S[i:(i + 4)] == "pain": print(c - 1) return print(-1) return if __name__ == '__main__': main()