s = gets.chomp.split("")
ln = s.length

rcnt = Array.new(ln,1)
id = ln-2
while id >= 0
  if s[id] == s[id+1]
    rcnt[id] = rcnt[id+1]+1
  end
  id -= 1
end

ans = 0
id = 0
flag = 0
cnt = 0
while id <= ln-(2*(ans+1))
  if s[id] == "J"
    flag = 1
    cnt += 1
  elsif flag == 1
    if s[id] == "O"
      for i in (ans+1)..cnt
        lv = cnt-i+ans+1
        if id-1+2*lv < ln
          idi = id+lv 
          if s[idi] == "I" && rcnt[id] == lv && rcnt[idi] >= lv
            ans = lv
            break
          end
        end
      end
    end
    flag = 0
    cnt = 0
  end
  id += 1
end
puts ans
