S = input() pon = 0 for i in range(len(S)): if S[i:i+3] == 'pon': pon += 1 if S[i:i+4] == 'pain': break print(-1 if pon <= 1 or i == len(S)-1 else pon-1)