S = input() pain = S.find("pain") if pain==-1: print(-1) exit() cnt = S[:pain].count("pon") if cnt>=2: print(cnt-1) else: print(-1)