s = input() s2 = s.replace("pain", "Y") s3 = s2.replace("pon", "X") # print(s3) res = -1 ok = False for c in s3: if c == "Y": ok = True break if c == "X": res += 1 if res == 0 or not ok: res = -1 print(res)