import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  val s = readLine.trim.toList
  println(
    countMaxK(s)
  )
  @tailrec
  def countMaxK(str: List[Char], j:Int = 0, o: Int = 0, i: Int = 0, current: Int = 0): Int = {
    str match {
      case Nil ⇒ current
      case 'J'::t if o == 0 ⇒ countMaxK(t, j + 1, 0, 0, current)
      case 'J'::t ⇒ countMaxK(t, 1, 0, 0, current)
      case 'O'::t if j > o ⇒ countMaxK(t, j, o + 1, 0, current)
      case 'I'::t if o > i ⇒ countMaxK(t, 0, o, i + 1, math.max(current, i + 1))
      case _::t ⇒ countMaxK(t, 0, 0, 0, current)
    }
  }
  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)
  }
}
