import Data.List

main = getLine >>= print . (\(nmax,nmin,_) -> quot (nmax + nmin) 2) . foldl accum (0,0,0)

accum (nmax,nmin,n) 'g' = (max nmax (n+1), nmin, n+1)
accum (nmax,nmin,n) 'p' = (nmax, min nmin (n-1), n-1)