s = input() i = s.find('pain') if i == -1: print(-1) exit() cnt = s[:i].count('pon') if cnt < 2: print(-1) else: print(cnt - 1)