str = input() p = 0 if "pain" in str: idx = str.find("pain") str = str[:idx] lenS = len(str) i = 0 while i < lenS: if str[i : i + 3] == "pon": p += 1 i += 3 else: i += 1 if p <= 1: print(-1) else: print(p - 1)