while n = STDIN.gets.to_i
	
	break if n == 0
	
	m = STDIN.gets.to_i
	line = STDIN.gets
	
	cnt = 0
	idx = 0
	ptn = "I"
	
	for i in 1..n do
		ptn += "OI"
	end
	
	while idx = line.index(ptn, idx)
		if(idx.nil?)
			break
		else
			cnt += 1
			idx += 1
		end
	end
		
	puts cnt
end