s = input()

p = 0

ans = 0

while p < len(s):

    joi = 'JOI'

    cnt = [0] * 3

    for i in range(3):

        while p < len(s) and s[p] == joi[i]:

            cnt[i] += 1

            p += 1



    if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]:

        ans = max(ans, cnt[1])



print(ans)
import re

s = input()



ans = 0

for joi_str in re.findall('(J*)(O*)(I*)', s):

    j = len(joi_str[0])

    o = len(joi_str[1])

    i = len(joi_str[2])

    if j >= o and o <= i:

        ans = max(ans, o)



print(ans)
s = input()
p = 0
ans = 0
while p < len(s):
    joi = "JOI"
    cnt = [0] * 3
    for i in range(3):
        while p < len(s) and s[p] == joi[i]:
            cnt[i] += 1
            p += 1
    if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]:
        ans = max(ans, cnt[1])
print(ans)

import re

s = input()
ans = 0
for joi_str in re.findall("(J*)(O*)(I*)", s):
    j = len(joi_str[0])
    o = len(joi_str[1])
    i = len(joi_str[2])
    if j >= o and o <= i:
        ans = max(ans, o)
print(ans)

+import re + -p = 0 -while p < len(s): -    joi = "JOI" -    cnt = [0] * 3 -    for i in range(3): -        while p < len(s) and s[p] == joi[i]: -            cnt[i] += 1 -            p += 1 -    if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]: -        ans = max(ans, cnt[1]) +for joi_str in re.findall("(J*)(O*)(I*)", s): +    j = len(joi_str[0]) +    o = len(joi_str[1]) +    i = len(joi_str[2]) +    if j >= o and o <= i: +        ans = max(ans, o)