object Main extends App {
  import scala.io.StdIn.{readLine}
  val n = readLine().toInt
  println(makeJOIOI(readLine().toList))
  def makeJOIOI(str:List[Char]):Int = {
    var pile = str
    var j = 0
    var i = 0
    var jo = 0
    var io = 0
    var joi = 0
    var ioi = 0
    var joio = 0
    var ioio = 0
    while (!pile.isEmpty){
      pile match{
        case 'J'::t ⇒
          pile = t
          j += 1
        case 'I'::t ⇒
          pile = t
          if (joio > 0){
            joio -= 1
            ioi += 1
            jo += 1
          }else if (ioio > 0){
            ioio -= 1
            ioi += 1
            io += 1
          }else if (jo > 0){
            jo -= 1
            joi += 1
          }else if (io > 0){
            io -= 1
            ioi += 1
          }else {
            i += 1
          }
        case 'O'::t ⇒
          pile = t
          if (i > 0){
            i -= 1
            io += 1
          }else if (j > 0){
            j -= 1
            jo += 1
          }else if (ioi > 0){
            ioi -= 1
            ioio += 1
          }else if (joi > 0){
            joi -= 1
            joio += 1
          }
      }
    }
    joi + ioi + joio + ioio
  }

}

