import core.stdc.stdio;
import std.stdio;

void main(){
	int n;
	scanf("%d",&n);
	char[] buf = new char[n+1];
	scanf("%s",buf.ptr);
	buf = buf[0..n];
	bool[] used = new bool[n];
	int[] op = new int[n];
	bool Solve(char[] data,int c){
		used[] = false;
		int ic=n;
		int a;
		for(int i=n-1;i>=0;i--)
			if(a<c&&data[i]=='O')
				while(--ic>i)
					if(!used[ic]&&data[ic]=='I'){
						used[ic]=true;
						used[i]=true;
						a++;
						break;
					}
		if(a!=c)
			return false;
		int os=0;
		foreach(int i,u;used)
			if(u&&data[i]=='O')
				op[os++]=i;
		int oi=-1;
		foreach(int i,u;used)
			if(!u&&data[i]!='O')
				while(++oi<os)
					if(op[oi]>i){
						a--;
						break;
					}
		return a==0;
	}
	int l,r=n+1;
	while(r-l>1){
		int m=(r+l)/2;
		if(Solve(buf,m))
			l=m;
		else
			r=m;
	}
	printf("%d\n",l);
}