S = input() n = len(S) pon = "pon" pon_ind = 0 pain = "pain" pain_ind = 0 cnt = 0 for i in range(n): if S[i] == pon[pon_ind]: pon_ind += 1 if pon_ind == 3: cnt += 1 pon_ind = 0 elif pon_ind > 0: pon_ind = 0 if S[i] == pain[pain_ind]: pain_ind += 1 if pain_ind == 4: if cnt < 2: print(-1) else: print(cnt - 1) exit() elif pain_ind > 0: pain_ind = 0 print(-1)