import Data.List

main :: IO ()
main = do
    s <- getLine :: IO String
    print . fst $ foldl' (\(c, l) q-> case (l>0, q) of
        (True, 'g') -> (c+1, l-1)
        (True, 'p') -> (c,   l-1)
        (False,'g') -> (c,   l+1)
        (False,'p') -> (c-1, l+1)) (0,0) s