import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  val s = readLine.trim
  val runLength = s.foldRight(Nil: List[JOI]){
    case ('J', J(l)::t) ⇒ J(l + 1)::t
    case ('O', O(l)::t) ⇒ O(l + 1)::t
    case ('I', I(l)::t) ⇒ I(l + 1)::t
    case ('J', t) ⇒ J(1)::t
    case ('O', t) ⇒ O(1)::t
    case ('I', t) ⇒ I(1)::t
    case _ ⇒ ???
  }
  println(
    countMaxK(runLength)
  )
  @tailrec
  def countMaxK(str: List[JOI], currentMax: Int = 0): Int = {
    str match {
      case J(j)::O(o)::I(i)::t if j >= o && o <= i ⇒ countMaxK(t, math.max(currentMax, o))
      case Nil ⇒ currentMax
      case h::t ⇒ countMaxK(t, currentMax)
    }
  }

  sealed trait JOI
  case class J(length: Int) extends JOI
  case class O(length: Int) extends JOI
  case class I(length: Int) extends JOI
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
