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