str = gets
arr = []
prev, n = str[0], 1
str[1..-1].each_char{|c|
    if c == prev
        n += 1
    else
        arr << [prev, n]
        prev, n = c, 1
    end
}
max, level, match = 0, level = 0, "J"
arr.each{|c, n|
    if c == "J"
        level = n
        match = "O"
    elsif c == "O"
        if match == "O" && n <= level
            level = [level, n].min
            match = "I"
        end
    else
        if match == "I" && n >= level
            level = [level, n].min
            max = level if max < level
        end
        match = "J"
    end
}
puts max
