#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  string s;
  map<char, int> m;
  m['J'] = 0;
  m['O'] = 1;
  m['I'] = 2;
  while(cin>>s){
    s = "I" + s;
    int N = s.size();
    int cnt[3]={};
    int ans = 0;
    for(int i = 1; i < N; i++){
      int n = m[s[i]];
      int b = m[s[i-1]];
      if(n < b){
        REP(i, 3) cnt[i] = 0;
        if(n == 0) cnt[0]++;
      }else{
        cnt[n]++;
        if(cnt[0]>=cnt[1]&&cnt[1]==cnt[2]) ans = max(ans, cnt[1]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}
#include <iostream>
#include <string>
using namespace std;

int k = 0, sum = 0, a[1000000];
string s;

int main() {
	cin >> s;
	
	for(int i = 0; i < s.size(); i++){
		sum++;
		if(s[i] != s[i + 1]){
			for(int j = i - sum + 1; j <= i; j++){
				a[j] = sum;
				sum--;
			}
			sum = 0;
		}
	}
	
	for(int i = 0; i < s.size(); i++){
		if(a[i] > k && s[i] == 'J'){
			if(a[i + a[i]] == a[i] && s[i + a[i]] == 'O' && a[i + a[i] * 2] >= a[i] && s[i + a[i] * 2] == 'I'){
				k = a[i];
			}
		}
	}
	
	cout << k << endl;
	
	return 0;
}