c=f=0 for i in input().replace("pon"," pon ").replace("pain"," pain ").split(): c+=i.count("pon") if"pain"in i: f=1 break print(c-1if f else -1)