s = gets.chomp
chunks = []
s.each_char{|c|
	if chunks.empty? || c != chunks[-1][0]
		chunks << [c, 1]
	else c == chunks[-1][0]
		chunks[-1][1] += 1
	end
}
max = 0
chunks.each_cons(3){|c1, c2, c3|
	if c1[0] == ?J && c2[0] == ?O && c3[0] == ?I
		k = c2[1]
		next if c1[1] < k || c3[1] < k
		max = k if k > max
	end
}
p max