#include <bits/stdc++.h>
using namespace std;
int main() {
	char str;
	int n[3]={},ans=0,x;
	while(cin>>str){
		if(str=='J'&&n[1]==0&&n[2]==0)n[0]++;
		else if(str=='O'&&n[1]<n[0]&&n[2]==0)n[1]++;
		else if(str=='I'&&n[2]<(x=min(n[0],n[1]))){
			n[2]++;
			if(n[2]==x)ans=max(ans,x);
		}
		else{
			for(int i=0;i<3;i++)n[i]=0;
			if(str=='J')n[0]=1;
		}
	}
	cout<<ans<<endl;
}
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    string str;
    int ret=0;
    vector<pair<char,int> > v;
    cin >> str;

    int cnt=1;
    char tmp=str[0];
    for(int i=1;i<str.size();++i){
        if(str[i] == tmp){
            cnt++;
        }else{
            v.push_back(make_pair(tmp,cnt));
            cnt=1;
            tmp = str[i];
        }
    }
    v.push_back(make_pair(tmp,cnt));
    for(int i=0;v.size() >=3 && i<v.size()-2;++i){
        if(v[i].first == 'J' &&
           v[i+1].first == 'O' &&
           v[i+2].first == 'I'){
            if(v[i].second >= v[i+1].second &&
               v[i+2].second >= v[i+1].second){
                ret = max(ret, min(v[i].second, min(v[i+1].second,v[i+2].second)));
            }
        }
    }
    cout << ret << endl;
}