#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cl[1000000][2];
int main(void){
	ll i,len,lv,cnt,p,pp,x;
	char s[1000001];
	cin>>s;
	len=strlen(s);
	for(i=0;i<len;i++) cl[i][1]=0;
	cnt=1; p=0; pp=0;
	if(s[0]=='J') cl[0][0]=0;
	else if(s[0]=='O') cl[0][0]=1;
	else cl[0][0]=2;
	for(i=0;i<len;i++){
		if(s[pp]!=s[i]){
			p++; pp=i;
			if(s[pp]=='J') cl[p][0]=0;
			else if(s[pp]=='O') cl[p][0]=1;
			else cl[p][0]=2;
		}
		cl[p][1]++;
	}
/*	for(i=0;i<=p;i++) cout<<cl[i][1]<<' ';
	cout<<endl;*/
	lv=0;
	for(i=1;i<len-1;i++){
		if(cl[i][0]==1){
			x=cl[i][1];
			if(cl[i-1][0]==0&&cl[i+1][0]==2){
				if(cl[i-1][1]>=x&&cl[i+1][1]>=x) lv=max(lv,x);
			}
		}
	}
	cout<<lv<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
	string s, t = "JOI";
	cin >> s;
	s += 'X';
	int ans = 0, f = -1, now = 0, pre = 0;
	rep(i, 0, s.size()) {
		if (s[i] == t[f]) {
			now++;
		}
		else if (f == 0 && s[i] == t[1]) {
			pre = now;
			now = 1;
			f = 1;
		}
		else if (f == 1 && s[i] == t[2]) {
			if (pre < now) {
				f = -1;
			}
			else {
				f++;
				pre = now;
				now = 1;
			}
		}
		else if (f == 2 && s[i] != t[2]) {
			if (pre <= now) ans = max(ans, pre);
			f = -1;
		}
		else {
			f = -1;
		}
		if (f == -1 && s[i] == 'J') {
			f = 0;
			now = 1;
		}
	}
	cout << ans << endl;
}