object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  var p = 0
  var ans = 0
  for (c <- s) {
    c match {
      case 'g' =>
        if (p > 0) {
          p -= 1
          ans += 1
        } else {
          p += 1
        }
      case 'p' =>
        if (p > 0) {
          p -= 1
        } else {
          p += 1
          ans -= 1
        }
    }
  }
  println(ans)
}