#include <cstdio>
 
using namespace std;
 
char s[1000001];
int Ipos[1000001];
 
int main()
{
	int N;
	
	scanf("%d", &N);
	scanf("%s", s);
	
	int ctr = 0;
	for (int i = N - 1; i >= 0; i--){
		if (s[i] == 'I') Ipos[++ctr] = i;
	}
	
	int left = 0, right = N;
	
	while (left != right){
		int center = (left + right + 1) / 2;
		
		int Jnum = 0, Onum = 0, Inum = 0;
		
		for (int i = 0; i < N; i++){
			if (s[i] == 'J' || (i < Ipos[center] && s[i] == 'I'))  Jnum++;
			if (s[i] == 'O' && Onum < Jnum) Onum++;
			if (s[i] == 'I' && Inum < Onum && i >= Ipos[center]) Inum++;
		}
		
		if (Jnum >= center && Onum >= center && Inum >= center) left = center;
		else right = center - 1;
	}
	
	printf("%d\n", left);
	
	return (0);
}