let solve gpLst =
    let rec solve' gCnt pCnt lst result =
        match lst with
        | [] -> result
        | x::xs ->
            let nextGCnt, nextPCnt, nextResult =
                match x, gCnt > pCnt with
                | 'g', true -> gCnt, pCnt + 1, result + 1
                | 'g', false -> gCnt + 1, pCnt, result
                | 'p', true -> gCnt, pCnt + 1, result
                | _, _ -> gCnt + 1, pCnt, result - 1
            solve' nextGCnt nextPCnt xs nextResult
    solve' 0 0 gpLst 0


let () =
    let gpLst = stdin.ReadLine() |> List.ofSeq
    solve gpLst |> printfn "%d"