def max(a, b)
  return a>b ? a : b
end
s = gets.chomp()
ans = 0
for i in 0..s.length-1 do
  if s[i]=='J' then
    c = 1
    while i+c<s.length && s[i+c]=='J' do
      c += 1
    end
    if i+c==s.length then
      break
    end
    if c<ans then
      next
    end
    for j in 0..c-1 do
      if s[i+c+j]!='O' then
        break
      end
      if j==c-1 then
        for k in 0..c-1 do
          if s[i+2*c+k]!='I' then
            break
          end
          if k==c-1 then
            ans = max(ans, c)
          end
        end
      end
    end
  end
end
puts ans